After a user has added some SKUs to the compare list, there is a page that lets them select two specific SKUs and do the side-by-side comparison. compare_bikes.jsp performs this functionality.

The form handler’s SkuCompareList property contains the list of the SKUs that have been added thus far. This list is used to populate two dropdown lists. The user selects one SKU from each of these dropdown lists.

Here is the code that displays a dropdown list with all of SKUs in the SkuCompareList property. The code uses the DSP tag library’s <dsp:select> tag for creating a dropdown list. The indexes (not the repository IDs) of the SKUs they select are stored in the form handler’s SelectedIndex1 and SelectedIndex2 properties. Here is the code for the first SKU dropdown list:

<!-- First dropdown list: -->
<!-- Display a drop down list of all Skus they can compare: -->
<!-- Store the index of their selection in the "SelectedIndex1" attribute  -->
<!-- in the CompareSkusFormHandler.                         -->
<dsp:select bean="CompareSkusFormHandler.SelectedIndex1">

<!-- For each Sku they can select: -->
<dsp:droplet name="/atg/dynamo/droplet/ForEach">
 <dsp:param bean="CompareSkusFormHandler.SkuCompareList" name="array"/>
 <dsp:param name="elementName" value="Sku"/>
 <dsp:oparam name="output">

  <!-- If this sku is selected, save its list INDEX in SelectedIndex1 -->
  <dsp:getvalueof id="option92" param="index" idtype="java.lang.Integer">
   <dsp:option value="<%=option92.toString()%>"/>
  </dsp:getvalueof>

  <!-- Display the name of the Sku in the dropdown: -->
  <dsp:valueof param="Sku.displayName"/>

 </dsp:oparam> <!-- output param for each Sku -->
</dsp:droplet> <!-- ForEach Sku -->

</dsp:select>

The above dropdown code for selecting the first SKU and almost identical code for selecting the second SKU are nested inside of a <dsp:form action> statement that includes the code for the Compare button. Here is the remaining code:

<dsp:form action="compare_bikes.jsp" method="POST">

   <!—Code for first dropdown list (see above) -->

   <!—Code for second dropdown list (see above)  -->

   <!-- COMPARE button: -->

   <dsp:input bean="CompareSkusFormHandler.compareSkus" type="submit" value="
        Compare   "/>

</dsp:form>

The first selected SKU for comparison can be referenced by indexing the skuCompareList. Likewise, the product with which the SKU is associated can be referenced in the same manner.

 
loading table of contents...