Value List Handler

Brief Description

Web applications frequently allow users to browse large virtual lists, such as query result sets, which can not practically be transmitted to the client. Access to the list is usually read-only and bi-directional, and the list is often discarded after the first few elements are examined. Using entity beans to represent elements of such lists provides little benefit and drains system resources. In particular, finder methods do not provide caching, scrolling, and random access to result sets, and have limited selection capabilities.

The Value List Handler design pattern provides a more efficient way to iterate a large, read-only list across tiers. A value list handler provides a client with an iterator for a virtual list that resides in another application tier. The iterator typically accesses a local ordered collection of Transfer Objects, representing a subrange of the large list. A Data Access Object usually manages access to the list data, and may provide caching.

Detailed Description

See the Core J2EETM Patterns

Detailed Example

The sample application catalog is an ordered collection of categories. Each category contains an ordered collection of products, and each product contains an ordered list of items. The catalog can also be searched for items that meet specific criteria.

Because it would be impractical to download the entire catalog each time the user selected a category, product, or item, or performed a search, the sample application manages catalog searching and browsing with the Value List Handler design pattern. The client requests information a page at a time by indicating where in the collection to begin and how many items to return. The client uses the value list handler as an iterator over the resulting collection and displays the result list in the user interface.

Figure 1 below shows a structure diagram of the sample application value list handler CatalogHelper.

Figure 1. Sample application CatalogHelper structure diagram

The CatalogHelper acts and as a value list handler for the client. The Client shown in Figure 1 is a JavaServer PagesTM (JSPTM) page, accessed through a Web browser, that accesses an instance of CatalogClientHelper using a useBean tag, as shown in the following excerpt from category.jsp:

        
<jsp:useBean
  id="catalog"
  class="com.sun.j2ee.blueprints.catalog.client.CatalogHelper"
  scope="session"
/>
      

A CatalogHelper instance, maintained in an HTTP session attribute, keeps track of:

  1. the current query being executed (if the page represents a search)
  2. the start position the list of elements being requested
  3. the number of list items to retrieve at a time
  4. the locale to be used for displaying the items

The CatalogHelper delegates responsibility for data access to an object that implements interface CatalogDAO (see the Data Access Object design pattern for details). The CatalogDAO retrieves a range of categories, products, items, or query results from the catalog, and returns them as a Page object. A Page is a transfer object that is a collection of other transfer objects. It represents the list of requested elements from the catalog (categories, products, or items). The CatalogHelper returns a Page of catalog entries (built by the CatalogDAO) to the client for display.

Figure 2 is a collaboration diagram of how the CatalogHelper uses a CatalogDAO to access a subrange of query results. Following the figure is a description of the method call sequence.

Figure 2. Collaboration diagram for value list handler CatalogHelper

This implementation illustrates several interesting points about the Value List Handler pattern:


Copyright © 2002 Sun Microsystems, Inc. All Rights Reserved.