As previously described, the Entry object maintains category, product, SKU, and inventory information in a single object. ProductComparisonList maintains a list of Entry objects, with each Entry object representing a product that the user has added to her product comparison list.

You can subclass ProductComparisonList and override its createListEntry method to extend the information stored in an Entry object. Although the Entry class contains convenience methods for setting and getting properties like product, category, sku, and inventoryInfo, your subclasses don’t need to provide similar methods for their own properties. Because Entry is a subclass of java.util.HashMap, you can call Entry.put(name, value) to add a new property value to the Entry object. The following code example illustrates this point; it stores a hypothetical value called “popularity,” which indicates how popular a given product is.

public class MyProductComparisonList extends ProductComparisonList
    protected Entry createListEntry(RepositoryItem pCategory,
                                    RepositoryItem pProduct,
                                    RepositoryItem pSku) {
      Entry e = super.createListEntry(pCategory, pProduct, pSku);
      int score = computePopularity(pProduct);
      e.put("popularity", score);
      return e;

    public int computePopularity(RepositoryItem pProduct) {

Note that by the time the createListEntry method is called, pCategory and pSku will have been populated with the product’s default parent category and first child SKU, if necessary and available. Consequently, createListEntry is called with the same category and SKU values that the user ultimately sees on the page in the product comparison list.

Page developers can refer to the popularity property of a ProductComparisonList entry to display the corresponding value in a JSP.

loading table of contents...