Pager Taglib
Overview
The PagerTag allows you to display lists of things as pages, much like the results from a search engine like Google.
It is designed to require minimal changes to a JSP page to support paging and provides convenient mechanisms for rendering an index strip that includes a Previous link, a Next link and optionally links to individual pages.
Usage Example
Producing a page display of lists is based on an object implementing the IPageable interface. Any object may implement that interface but most typically a java.util.List will also implement IPageable.
Modifying a JSP Page
Given an IPageable object it becomes straightforward to render it as a paged list. For example, consider a session scoped bean called searchResults that implements IPageable. Here is how to display it as a paged list in a JSP page:
String myPageURL = SessionManager.getJSPRootURL() + "MyPage.jsp";
<pg:pager name="searchResults" scope="session" pageSize="3">
<xml:transform name="searchResults"
scope="session"
stylesheet="somestylesheet.xsl" />
<pg:index href='<%=myPageURL%>'
stylesheet="/base/xsl/PagerPageIndex.xsl"
maxLinks="20" />
</pg:pager>
Note 1: Neither the PagerTag nor the IPageable interface specify how paged results are displayed; the <xml:transform /> is shown here as an example. In this case the searchResults object has committed to using the pageIterator as defined by the IPageable interface to return XML.
Note 2: There is a default stylesheet located at /base/xsl/PagerPageIndex.xsl.
Navigating from Page to Page
When rendered, the index may look something like this:
Result Page: < Previous 1 2 3 4 5 6 7 8 Next >
This is returned by the default stylesheet.
Clicking a link will navigate to the URL specified by the href attribute of the index tag. Note that there is an additional parameter added to the URL called page_start which is read by the pager tag to determine which page to display. In most cases it is sufficient to pass the current page relative URL as the href attribute for paging to work.
Tag Summary
- pager - Initializes the IPageable object and sets the page size. Processes the request to determine which page to display.
- index - Renders the pager index links with Next and Previous links.
Tag Reference
pager
Initializes the IPageable object and sets the page size. Processes the request to determine which page to display.
- Tag Body JSP
- Restrictions None
- Attributes
| Name | Required | Runtime Expression Evaluation | Description |
| name | Yes | Yes | Attribute name of an IPageable object. This object will usually be a session scoped object to support repeated iteration through its page results. The pager tag does not exist beyond page scope. |
| scope | No | Yes | Scope in which named attribute is found. Default is page scope. |
| pageSize | Yes | Yes | Number of items to show per page. |
- Variables None
- Examples
Initialize a session scoped IPageable object with 10 items per page and process the current request parameter to determine:
<pg:pager name="myObjectName" scope="session" pageSize="10" />
Initialize a paged scoped IPageable object with 5 items per page:
<pg:pager name="myObjectName" pageSize="5" />
index
Renders the pager index links with Next and Previous links.
- Tag Body Empty
- Restrictions Must be with pager tag
- Attributes
Name Required Runtime Expression Evaluation Description href Yes Yes The HREF to include on all links for Next, Previous and page navigation stylesheet Yes Yes The path to the stylesheet to use for rendering the pager index maxLinks No Yes The maximum number of index links to display. Default is 20. displayIf No Yes Specifies whether to render any output
- Variables None
- Examples Render the index with a maximum of 20 links (Google-style):
<pg:index href='<%=myURL%>' stylesheet="/base/xsl/PagerPageIndex.xsl" maxLinks="20" />
