<%@ page contentType="text/html" pageEncoding="windows-1252" import="javax.portlet.*,
                 java.util.*,
                 portlet.ProductsBean,
                 portlet.ProductDetailsBean,
                 portlet.ProductsService,
                 portlet.Products "%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>

<!-- Include the Portlet render Response & Request objects -->
<portlet:defineObjects/>

<%
    // Get the list of products
    ProductsBean products = new ProductsService().getProducts();
    ArrayList<ProductDetailsBean> productDetails = products.getProducts();

    // "Portlet encode" the Action URL if running Portlet mode
    String actionURL = "view.jsp";
    if (renderResponse != null) {
      actionURL = renderResponse.createActionURL().toString();
    }
    
    // Extract the current portlet parameter value if running in Portlet mode
    String param1 = "";
    if (renderRequest != null) {
      param1 = renderRequest.getParameter(Products.PARAMETER1);
      if (param1 == null) { param1 = ""; } 
    }
%>
<form method="POST" action="<%= actionURL %>">
 <table>
  <tr>
   <th>Select</th>
   <th>Product</th>
   <th>Product supplied by</th>
   <th>Our price</th>
  </tr>
   
  <%
   for (int i = 0; i < productDetails.size(); i++) {
      ProductDetailsBean productDetail = productDetails.get(i);
%>
   
  <tr>
   <td align="center">
    <!-- Set the Form parameter name to passed as a render parameter during processAction -->
    <input type="radio" name="<%= Products.FORM_PARAMETER1 %>"
           value="<%=productDetail.getProductId()%>"
           <%= param1.equals(productDetail.getProductId()) ? " checked='checked'" : "" %>/>
   </td>
   <td>
    <%=productDetail.getProductName()%>
   </td>
   <td>
    <%=productDetail.getSupplierName()%>
   </td>
   <td align="right">
    $<%=productDetail.getProductPrice()%>
   </td>
  </tr>
   
  <% } %>
   
  <tr class="PortletText1">
   <td>
    <input name="<%= Products.FORM_SUBMIT %>" type="submit"
           class="portlet-form-button" value="Show Details"></input>
   </td>
   <td colspan="3">&nbsp;</td>
  </tr>
   
 </table>
 
 <!-- create a hidden parameter to note we're running in "view" mode -->
 <input type="hidden" name="<%= Products.MODE_NAME_PARAM %>" 
        value="<%= Products.MODE_VIEW %>"/>
</form>