<%@ page import="oracle.jsp.webutil.personalization.Item" errorPage="error.jsp" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jml.tld" prefix="jml" %>
<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/personalization.tld" prefix="op" %>

<html>
<head><title>Personalization Demo</title></head>
<body>
<b><font size=+1>selectFromHotPicks with getNextItem Tags</font></b>
<p>
<font color="#FF0000">Using getNextItem nested tags for results </font><br>


<%
   String getNextMode = request.getParameter("getNextMode");
   String sortOrder = request.getParameter("sortOrder");
   String maxQ = request.getParameter("maxQ");
   String from = request.getParameter("from");
   String fromHPG = request.getParameter("fromHPG");
   String useList = request.getParameter("useList");
   boolean useResList = ((useList== null)? false :useList.equals("true"));

   Item[] items = null;
   String typ = null;
   String ID = null;
   Item item = null;

 if(getNextMode != null) {
   if(getNextMode.equals("fixedNo")) { 
      if(useResList){ %>
<op:selectFromHotPicks storeResultsIn="results"
                       hotPicksGroups="<%=fromHPG%>" >
  <op:getNextItem storeTypeIn="typ" storeIDIn="ID" />
  <li>Next: type=<%=typ%>&nbsp;ID=<%=ID%></li>
  <op:getNextItem storeItemIn="item" />
  <li>Next item: type=<%=item.getType()%>&nbsp;ID=<%=Long.toString(item.getID())%></li>
  <op:getNextItem storeTypeIn="typ" storeIDIn="ID" />
  <li>Next: type=<%=typ%>&nbsp;ID=<%=ID%></li>
  <op:getNextItem storeItemIn="item" />
  <li>Next item: type=<%=item.getType()%>&nbsp;ID=<%=Long.toString(item.getID())%>&nbsp;Prediction=<%=Float.toString(item.getPrediction())%></li>
  <op:getNextItem storeTypeIn="typ" storeIDIn="ID" />
   <li>Next: type=<%=typ%>&nbsp;ID=<%=ID%></li>
</op:selectFromHotPicks>
<% items = results;
      } else {  %>
<op:selectFromHotPicks hotPicksGroups="<%=fromHPG%>" >
  <op:getNextItem storeTypeIn="typ" storeIDIn="ID" />
  <li>Next: type=<%=typ%>&nbsp;ID=<%=ID%></li>
  <op:getNextItem storeItemIn="item" />
  <li>Next item: type=<%=item.getType()%>&nbsp;ID=<%=Long.toString(item.getID())%></li>
  <op:getNextItem storeTypeIn="typ" storeIDIn="ID" />
  <li>Next: type=<%=typ%>&nbsp;ID=<%=ID%></li>
  <op:getNextItem storeItemIn="item" />
  <li>Next item: type=<%=item.getType()%>&nbsp;ID=<%=Long.toString(item.getID())%>&nbsp;Prediction=<%=Float.toString(item.getPrediction())%></li>
  <op:getNextItem storeTypeIn="typ" storeIDIn="ID" />
   <li>Next: type=<%=typ%>&nbsp;ID=<%=ID%></li>
</op:selectFromHotPicks>
<% }   
  } else {
  if(fromHPG != null) {
     String type = null;
     String id = null;
%>
<p><font color="#FF0000"> results from <code>getNextItem</code> in a loop: </p></font>
<%   if(useResList) { %>
<op:selectFromHotPicks hotPicksGroups="<%=fromHPG%>"
                       storeResultsIn="results"
                       maxQuantity="<%=maxQ%>"
                       sortOrder="<%=sortOrder%>" >
  <%  while(true) { %>
       <op:getNextItem storeTypeIn="type" storeIDIn="id" />
       <% if(type==null) break; %>
       <li>Next: type=<%=type%>&nbsp;ID=<%=id%></li>
  <% } %>
</op:selectFromHotPicks>
<% items = results;
     } else { %>
<op:selectFromHotPicks hotPicksGroups="<%=fromHPG%>"
                       maxQuantity="<%=maxQ%>"
                       sortOrder="<%=sortOrder%>" >
  <% while(true) { %>
       <op:getNextItem storeItemIn="item" />
       <% if(item==null) break; %>
       <li>Next item: type=<%=item.getType()%>&nbsp;ID=<%=Long.toString(item.getID())%>&nbsp;Prediction=<%=Float.toString(item.getPrediction())%></li>
  <% } %>
</op:selectFromHotPicks>
<% }}} 
   if(useResList){
%>
<br><font color="#FF0000"> ...as well as storeResultsIn variable </font><br>
<p>Here are same items accessed from <code>storeResultsIn</code> array:</p>

<table border=1>
<tr><td><b>&nbsp;Type</b></td><td><b>&nbsp;ID</b></td>
<td><b>&nbsp;Prediction</b></td></tr>
<jml:for id="i" from="0" to="<%= items.length-1 %>" >
<tr><td><%=items[i.intValue()].getType()%></td><td><%=items[i.intValue()].getID()%></td>
<td><%=items[i.intValue()].getPrediction()%></td></tr>
</jml:for>
</table>
<% } %>
<hr>
<% } %>

<form action="tagdemodriver.jsp" method="post">
<input type="hidden" name="target" value="Return"/>
<input type="submit" name="Choose another tag" value="Choose another tag"/>
</form>

<p>
<form action="selectfromhpasnext.jsp" method="get">
<table>

<tr><td><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; How to use <code>getNextItem</code> tag: </b></td> </tr>

<tr><td><label><input type="radio" name="getNextMode" value="loop" checked><b>Loop</b> </label></td>
<td><label><input type="radio" name="getNextMode" value="fixedNo" > <b>Fixed number if tags</b></label></td>
</tr>

<tr><td> &nbsp;</td>
<td> When fixed number of <code>getNextItem</code> tags is chosen, default <code>maxQuantity</code> value (5) will be used. </td>
</tr>

<tr><td><label><b> use <code>storeResultsIn</code> list as well?</b> <input type="checkbox" name="useList" value="true" checked></label></td>

<tr>
<td><label><b>Hot Picks Groups </b><input type="text" name="fromHPG"/></label></td>
</tr>

<tr><td><b>sortOrder:</b> </td><td><select name="sortOrder">
<option value="NONE">NONE</option>
<option value="">no value</option>
<option value="DESCEND">DESCEND</option>
<option value="ASCEND">ASCEND</option>
</select></td></tr>
<tr><td><b>maxQuantity:</b> <input type="text" size=2 name="maxQ" /> </td>
</tr>
</table>
<input type="submit" name="submit" value="Submit"/>
</form>

</body>
</html>
