Jakarta Project: Iterators Tag library

Version: 1.0

Table of Contents

Overview

This tag library includes useful iteration tags that complement the set of standard iterator tags of the JSP Standard Tag Library (JSTL).

<forCategories>

This iterator tag is exactly like <forEach>, with the addition that it supports the concept of categories. For instance, in the example below, the collection contains a list of athletes sorted by their associated country. By using the <forCategories> tag, it is possible to display distinctive headers and footers whenever a new country is encountered in the list.

  <iter:forCategories var="athlete" items="${athletes}">
    <iter:category value="${athlete.country}">
      <iter:header>
        <h3><c:out value="${athlete.country}"/></h3>
      </iter:header>
      <iter:body>
        <c:out value="${athlete.name}"/><br>
      </iter:body>
      <iter:footer>
        ----
      </iter:footer>
    </iter:category>
  </iter:forCategories>
Canada
De Zwirek, Jeremie
Harvey, Pierre
----
France
De LaSalle, Jean-Yves
Marcoux, Pierre
Surinam, Jean-Francois
----

<forColumns>

This iterator tag allows the handling of the items of a collection in a columnwise fashion. Each iteration makes available as many items as there are columns, and they are provided such that the ordering sequence is column-wise.

For instance, in the example below, the collection contains a list of athletes sorted by their name. By using the <forColumns> tag, it is possible to display the items of the collection in multiple columns, keeping the display order on a column by column basis.

<table border="1" cellspacing="5">
<iter:forColumns var="athlete" items="${athleteNames}" columns="4">
  <tr>
    <td><c:out value="${athlete[0].lastName}" default=""/>,
        <c:out value="${athlete[0].firstName}" default=""/></td>
    <td><c:out value="${athlete[1].lastName}" default=""/><c:if test="${!empty athlete[1]}">,</c:if>
        <c:out value="${athlete[1].firstName}" default=""/></td>
    <td><c:out value="${athlete[2].lastName}" default=""/><c:if test="${!empty athlete[2]}">,</c:if>
        <c:out value="${athlete[2].firstName}" default=""/></td>
    <td><c:out value="${athlete[3].lastName}" default=""/><c:if test="{!empty athlete[3]}">,</c:if>
        <c:out value="${athlete[3].firstName}" default=""/></td>
  </tr>
</iter:forColumns>
</table>
Armstrong, Lance Delisle, Laurence Hineault, Bernard Puhjo, Dimas
Biondi, Matt Fitzgerald, Thomas Le Potiron, Jerome St-Gelais, Vincenzo
Bonnehumeur, Marc Garcia, Bruno LeFrancois, Jean-Marie Zalluci, Frederico
Borg, Boris Guttenberg, Moritz Muller, Hans
Chenard, Line Hallenbuch, Katherine Pellegri-Llopart, Eduardo
De Zwirek, Jeremie Harvey, Pierre Poirot, Hercule

Requirements

This custom tag library requires a servlet container that supports the JavaServer Pages Specification, version 1.2 or higher. It also requires the JSP Standard Tag Library (JSTL).

Configuration

Follow these steps to configure your web application with this tag library:

To use the tags from this library in your JSP pages, add the following directive at the top of each page:

<%@ taglib uri="http://jakarta.apache.org/taglibs/iterators-1.0" prefix="foo" %>

where "foo" is the tag name prefix you wish to use for tags from this library. You can change this value to any prefix you like.

Tag Summary

Iterator Tags
forCategories
category
body
header
footer
forColumns
 

Tag Reference

forCategories Availability: 
Tag BodyJSP    
Restrictions None
AttributesNameRequired Runtime Expression Evaluation Availability
 items  No   No  
 
 begin  No   No  
 
 end  No   No  
 
 step  No   No  
 
 var  No   No  
 
 varStatus  No   No  
 
VariablesNone
ExamplesNone
category Availability: 
Tag BodyJSP    
Restrictions None
AttributesNameRequired Runtime Expression Evaluation Availability
 value  Yes   No  
 
 label  No   No  
 
VariablesNone
ExamplesNone
body Availability: 
Tag BodyJSP    
Restrictions None
AttributesNone
VariablesNone
ExamplesNone
header Availability: 
Tag BodyJSP    
Restrictions None
AttributesNone
VariablesNone
ExamplesNone
footer Availability: 
Tag BodyJSP    
Restrictions None
AttributesNone
VariablesNone
ExamplesNone
forColumns Availability: 
Tag BodyJSP    
Restrictions None
AttributesNameRequired Runtime Expression Evaluation Availability
 items  No   No  
 
 var  No   No  
 
 varStatus  No   No  
 
 columns  Yes   No  
 
VariablesNone
ExamplesNone

Examples

See the example application iterators-examples.war for examples of the usage of the tags from this custom tag library.

Java Docs

Java programmers can view the java class documentation for this tag library as javadocs.

Revision History

Review the complete revision history of this tag library.