This JSP fragment shows how to add or remove a single product from a product comparison list. The example assumes that the ProductListContains servlet bean is embedded in a product display page using the following:

<dsp:include page="example.jsp"><dsp:param name="product"
     value="current product"/></dsp:include>

where current product is an expression that provides access to the product displayed on the page.

The given product is passed into the servlet bean in the productId input parameter. The ProductListContains servlet bean then checks whether it is stored in the product comparison list in ProductList. If the product is in the product comparison list, then the servlet bean renders the true open parameter on the product display page, and the user can click the “Remove from comparison list” submit button to remove the product from the list. If the product is not in the product comparison list, then the servlet bean renders the false open parameter on the product display page, and the user can click the “Add to comparison list” submit button to add the product to the list.

<dsp:importbean bean="/atg/commerce/catalog/comparison/ProductList"/>
<dsp:importbean bean="/atg/commerce/catalog/comparison/ProductListContains"/>
<dsp:importbean bean="/atg/commerce/catalog/comparison/ProductListHandler"/>

<dsp:form action="product.jsp" method="POST">
<dsp:droplet name="ProductListContains">
  <dsp:param bean="ProductList" name="productList"/>
  <dsp:param param="product.repositoryId" name="productID"/>

  <dsp:oparam name="true">
    <dsp:input bean="ProductListHandler.productID" paramvalue="productID"
         type="hidden"/>
    <dsp:input bean="ProductListHandler.removeProduct" value="Remove from
         comparison list" type="submit"/>
  </dsp:oparam>

  <dsp:oparam name="false">
    <dsp:input bean="ProductListHandler.productID" paramvalue="productID"
         type="hidden"/>
    <dsp:input bean="ProductListHandler.addProduct" value="Add to
      comparison list" type="submit"/>
  </dsp:oparam>

</dsp:droplet>
</dsp:form>