You can filter products from a collection using independent collection filters or filters in a chain. This example shows how to render a collection of products that satisfy the conditions defined in a chain of filters. The rendered collection is cached for future use.

Consider a Web page in which you want to display a list of active, available products to customers. To do this, use a collection filtering servlet bean (ProductFilterDroplet) in a JSP to access a collection filtering component (ProductFilter) that will then apply its chain of filters to a collection of products. See CollectionFilter for more on ProductFilterDroplet and other collection filtering servlet beans.

It is the responsibility of ProductFilter to chain together separate collection filters and to execute that chain. This example assumes that the ProductFilter.filters property identifies two collection filters: StartEndDateFilter and InventoryFilter. These filters collectively remove products that aren’t available for sale (StartEndDateFilter) and aren’t in stock (InventoryFilter).

The JSP code would look like this:

<dspel:droplet name="/atg/collections/filter/droplet/ProductFilterDroplet">
   <dsp:param name="collection" param="item.childproducts/>
   <dsp:param name="collectionIdentifierKey" value="catid-0067-hardscape"/>

   <dspel:oparam name="output">
   Featured Plants:<p>
      <dsp:droplet name="/atg/dynamo/droplet/ForEach">
         <dsp:param name="array" param="filteredCollection"/>

         <dsp:oparam name="output">
            <dspel:valueof param="element"/>
         </dspel:oparam>
      </dsp:droplet>
   </dspel:oparam>

   <dspel:oparam name="empty">
      There are currently no outdoor plants
   </dspel:oparam>
</dspel:droplet>

When this JSP executes, the ProductFilterDroplet passes the products to the ProductFilter component and executes the chain:

  • The first component is StartEndDateFilter, which compares the current date to the values in the startDate and endDate properties for each product. Products that are not active (have not been “started” or have already been “ended”) are discarded and the remaining products are passed to the InventoryFilter

  • InventoryFilter corresponds with the Inventory Manager to determine the availability of all products in the slot. Products that are out of stock are removed from the collection.

  • When caching is enabled on ProductFilter, the FilterCache component saves information that represents the prefiltered collection as well as the filtered result. Subsequent renderings of this JSP will compare the cached prefiltered collection with the current prefiltered one. When appropriate, the cached filtered result is used. For more information about caching, see the Filtering Collections chapter of the ATG Personalization Programming Guide.


Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved. Legal Notices