Custom JSP tag Repeater displays data items in a repeating list. This tag is similar to the Repeater control in ASP.NET. Similar to DataList, the content and layout of list items in Repeater is defined using templates. At a minimum, you must define an itemTemplate; however, the following optional templates may be used to customize the appearance of the list:
| Template Name | Description |
|---|---|
| itemTemplate | Defines the content and layout of items within the list. |
| alternatingItemTemplate | If defined, the alternatingItemTemplate determines the content and layout of alternating items. If not defined, itemTemplate is used. |
| separatorTemplate | If defined, the separatorTemplate is rendered between items (and alternating items). If not defined, a separator is not rendered. |
| headerTemplate | If defined, the headerTemplate determines the content and layout of the list header. If not defined, header is not rendered. |
| footerTemplate | If defined, the footerTemplate determines the content and layout of the list footer. If not defined, footer is not rendered. |
Unlike DataList, Repeater has no built-in layout or styles. You must explicitly declare all HTML layout, formatting, and style tags within the templates of the control. For example, to create a list within an HTML table, you might declare the <table> tag in the headerTemplate, a table row (<tr> tags, <td> tags) in the itemTemplate, and the </table> tag in the footerTemplate. It is similar to DataList tag with the following values: repeatColumns="1" repeatLayout="flow".
For example:
And you will get a commas separated list:
So this tag outputs itemTemplate (or alternatingItemTemplate) for each element in your datasource. Tag outputs separatorTemplate between elements.
You may add paging. Tag Repeater accepts also parameters from and to. From describes an index (or row in case of ResultSet) for first element. Default value is 1 (from the first position or first row). To describes an index for last element (row). Note: indexes always start from 1 (not from 0).
As a source you may use arrays, enumerations, iterators and ResultSets.
You may use this tag together with DB tags
also. For example:
Parameter type describes type for elements in your datasource. In itemTemplate and
alternatingItemTemplate you may use predefined variables CURRENT_VALUE and CURRENT_OBJECT.
Type for CURRENT_OBJECT is exactly what you set in parameter type. Type for CURRENT_VALUE
is java.lang.String. For example, suppose you have a vector of beans. You may use some like this:
Let we see more examples (integration with databases):
and you will get some like this:
1 Java 2 C++ 3 Basic 4 Prolog
You may integrate Repeater with DB tags. In this
case parameter source is some string describes query result and parameter type
must be com.cj.repeater.dbtag. Class com.cj.repeater.dbtag supports methods
getColumn(int index_for_column), getColumnName(int index_for_column), getColumnType(int index_for_column),
getColumnCount() that lets you read data. For example:
Tags are:
Repeater
Tag displays data items in a repeating list. Parameters are:
1) source Describes a data source.
Could be an array, iterator, enumeration, ResultSet or string. String describes
ID for query results if you are using DB tags.
2) type Optional parameter. Describes a type for
elements in datasource. Default value is java.lang.String. For ResultSet it must be
java.sql.ResultSet, for DB tag ID it must be com.cj.repeater.dbtag
3) from Optional parameter. Describes an initial
element (position) for loop through datasource (row in ResultSet). Starts with 1. Default
value is 1 (first element or first row).
4) to Optional parameter. Describes a last element
(position) for loop through datasource (row in ResultSet). By default tag scans all elements
or rows (up to last position or row).
headerTemplate
Body tag describes a template for header. Parameters are: none
footerTemplate
Body tag describes a template for footer. Parameters are: none
separatorTemplate
Body tag describes a template for separator. Parameters are: none
itemTemplate
Body tag describes a template for items. Parameters are: none
alternatingItemTemplate
Body tag describes a template for items in other rows. Parameters are: none
for downloading:
Library: repeater.jar Description: taglib.tld
See also Coldtags suite - the largest collection of custom JSP tags.