Custom JSP taglib lets you implement grids (tables) in your applications. As a source of data you can use ResulSets for JDBC requests, arrays, iterators, enumerations. Also you can use this tag together with DB taglib from Coldtags suite.
Grid includes (may include) header, body (set of rows) and footer.
By default tag grid automatically (parameter autoGenerateColumns)
outputs data columns. So, for example, in the simplest case you can write some like this:
and you will get some like this
ID | Name | Qty |
120 | Part 1 | 5 |
121 | Part 2 | 8 |
156 | Part 7 | 0 |
You can set parameter autoGenerateColumn to false and define your
headers and columns. You can use nested variable rowData as a reference to the current
data and rowNumbner as a reference to the current row number. Body tag rows
executes own body for the each element in your datasource. For example:
Data | Row |
A | 1 |
B | 2 |
C | 3 |
You can set your own style for the each other row (parameter is alternatingStyle or alternatingClassName). For example:
Data | Row |
A | 1 |
B | 2 |
C | 3 |
You do not need special tags (like ButtonColumn in .NET) for HTML forms in your grid. You can use any
JSP (HTML) code in columns tag. For example:
Data | Check Box |
And of course, you can define your own custom type for rowData variable. So for example if it is your bean, you can write some like rowData.callMethod() in your tags.
For publishing your databases you can use grid with DB taglib. In this case data type for rowData must be com.cj.grid.dbtag. For this type you can use the following methods:
getColumn(int columnNumber) returns data
getColumnName(int columnNumber) returns a name for column
getColumnType(int columnNumber) returns a type for column
getColumnCount() what's the number of columns in the ResultSet?
For example:
or with your own definitions:
Tags are:
grid
Body tag, outputs a table (grid). 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.Object. For ResultSet it must be java.sql.ResultSet, for DB tag ID it must be com.cj.grid.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. 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).
5) width Optional parameter. Describes a width for this table
6) height Optional parameter. Describes a height for this table
7) autoGenerateColumns Optional parameter. Possible values are true or false.
Default value is true.
8) style Optional parameter. Describes a CSS style
9) className Optional parameter. Describes a CSS class
10) borderWidth Optional parameter. Describes a width for border
11) borderColor Optional parameter. Describes a color for border
12) cellSpacing Optional parameter. Describes a cellspacing parameter for this table
13) cellPadding Optional parameter. Describes a cellpadding parameter for this table
14) idRowData Optional parameter. Describes a name for nested page scope variable with the first element
from your datasource (first row).
headers
Body tag, outputs headers. Parameters are:
1) style Optional parameter. Describes a CSS style
2) className Optional parameter. Describes a CSS class
footers
Body tag, outputs footers. Parameters are:
1) style Optional parameter. Describes a CSS style
2) className Optional parameter. Describes a CSS class
rows
Body tag, outputs rows. Tag executes own body for the each element in your data source. Parameters are:
1) style Optional parameter. Describes a CSS style
2) className Optional parameter. Describes a CSS class
3) alternatingStyle Optional parameter. Describes a CSS style for other rows
4) alternatingClassName Optional parameter. Describes a CSS class for other rows
5) idRowNumber Optional parameter. Describes a name for nested page scope variable with row number.
Type for this variable is java.lang.Integer. Default name (default value for this parameter) is rowNumber.
6) idRowData Optional parameter. Describes a name for nested page scope variable with current row's data
(current element in datasource). Default name (default value for this parameter) is rowData.
7) type Optional parameter. Describes a type for elements in datasource.
Default value is java.lang.Object. For ResultSet it must be java.sql.ResultSet, for DB tag ID it must be com.cj.grid.dbtag
column
Body tag, outputs column (for rows, headers, footers). Parameters are:
1) style Optional parameter. Describes a CSS style
2) className Optional parameter. Describes a CSS class
3) width Optional parameter. Describes a width for this column
4) height Optional parameter. Describes a height for this column
5) horizontalAlign Optional parameter. Describes a horizontal align. Possible values are
left, right, center.
6) verticalAlign Optional parameter. Describes a vertical align. Possible values are
top, bottom, middle.
7) colspan Optional parameter. Describes a colspan parameter for column. Default value is 1.
8) rowspan Optional parameter. Describes a rowspan parameter for column. Default value is 1.
9) nowrap Optional parameter. Describes a nowrap parameter for column. Possible values are
true or false. Default value is false.
for downloading:
Library: gridtag.jar Description: taglib.tld
See also Coldtags suite - the largest collection of custom JSP tags.