The store.war/browse/gadgets/recentlyViewed.jsp gadget is responsible for rendering the Recently Viewed panel at the bottom of the product detail page. For each recently viewed product, recentlyViewed.jsp renders the product name, image, pricing, and site the product was viewed on. Also, each recently viewed product in the panel is rendered as a link that takes the customer to the product detail pages for the individual products.

To do its job, recentlyViewed.jsp uses the RecentlyViewedFilterDroplet to generate a filtered collection of recently viewed products that are appropriate for the current site context. As described in Filtering Products in the Recently Viewed List, the RecentlyViewedFilterDroplet can take an exclude parameter so that any specified products are excluded from the recently viewed products list. Commerce Reference Store’s implementation of the product detail page takes advantage of this mechanism to prevent the currently displayed product from also appearing in the recently viewed products list. To do this, the product detail page specifies the current product’s ID in an exclude page parameter when it calls recentlyViewed.jsp, and then recentlyViewed.jsp passes the excluded product to the RecentlyViewedFilterDroplet.

The RecentlyViewedDroplet calls RecentlyViewedFilter to do the actual filtering. RecentlyViewedFilter returns the filtered list of recently viewed products in descending timestamp order so that the most recently viewed product is returned first, the second most recently viewed product is returned second, and so on. A ForEach servlet bean is used to iterate over the filtered list in this same order, so that the most recently viewed product is rendered farthest to the left and the least recently viewed product is rendered farthest to the right. The ForEach servlet bean’s output open parameter includes the generic gadget, store.war/global/gadgets/promotedProductRenderer.jsp, to render each recently viewed product, including its associated information and a link to its product detail page.

Note that the recently viewed product’s site ID is passed to the promotedProductRenderer.jsp gadget. The promotedProductRenderer.jsp gadget then forwards this site ID on to the gadget that renders the site indicator portion of the recently viewed product information, namely store.war/global/gadgets/siteIndicator.jsp. This is necessary because a product may be associated with more than one site and, if a site ID is not provided, siteIndicator.jsp will pick a site ID based on its own internal logic. In the case of a recently viewed product, we want the site indicator to represent the site the product was viewed on, so we must explicitly pass the recently viewed product’s site ID to siteIndicator.jsp.

On a final note, if RecentlyViewedFilter returns an empty list, the ForEach servlet bean terminates itself and the Recently Viewed panel is not rendered.

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