bitmechanic: listlib

Current version: 0.92

This library is released free of charge with source code included. See the LICENSE file for details.

Questions/Comments: Email James Cooper <pixel@bitmechanic.com>

This project is listed at: JSpin.com


Overview

listlib is a JSP 1.2 TagLib that makes it easy to build pages that have scroll through sets of information. The most common example of this is a search results page, where there are 100 hits, but you only want to show 20 per page.

To use listlib, you write an implemenation of the ListCreator interface. This implementation returns a ListContainer object that stores an Iterator with the list results, as well as the total size of the result set (so the taglib knows whether to allow the user to scroll forward or back).

Installation

Example

Here's an example JSP and ListCreator implementation:

Tag Reference

init

Start tag for listlib. Creates the ListCreator object, runs its execute() method, and stores the ListContainer in the HttpServletRequest attribute hash. This is a container tag, so all other tags should be nested inside of this one.

property description required
name Specifies what key to use when associating the ListContainer with the request via HttpServletRequest.setAttribute() yes
class Class of the ListCreator implementation to use no (this or initCreator must be specified)
listCreator Name in the HttpServletRequest attribute hash of a ListCreator object to use. Allows you to instantiate a ListCreator separately and set its properties before passing it into this taglib no (this or class must be specified)
max Integer specifying the maximum number of items the ListCreator should return per page yes

hasResults

If the list has results, then the body of this tag will be evaluated, otherwise it will be skipped. This tag accepts no parameters.

hasNoResults

If the list has no results, then the body of this tag will be evaluated, otherwise it will be skipped. This tag accepts no parameters.

prop

Convenience method that returns a property from the ListContainer tag associated with this list.

property description required
property Property on the ListContainer to display. Valid properties are: size, max, start, end, offset. yes

hasPrev

If the user can scroll backwards in the list, then the body of the tag will be evaluated, otherwise it will be skipped. This tag accepts no parameters.

hasNext

If the user can scroll forwards in the list, then the body of the tag will be evaluated, otherwise it will be skipped. This tag accepts no parameters.

prevLink

Returns a link to the current URI with a QUERY_STRING set to the proper offset to scroll backwards one page in the list. This tag accepts no parameters.

nextLink

Returns a link to the current URI with a QUERY_STRING set to the proper offset to scroll forwards one page in the list. This tag accepts no parameters.

iterate

Iterates through the items in the ListContainer. The body of this tag will be evaluated once per item. This tag accepts no parameters.

iterateProp

Returns a property from the current object in the Iterator.

property description required
property Property on the object to display. Object may be either a Map or a Java Bean. If it's a map, this tag calls get() with the property name, otherwise it calls a get method with the appropriate name (e.g. property="name" would result in a call to getName()) yes