Displays each element of an array, arranging the output in a two-dimensional format.
Class Name |
|
---|---|
Component |
|
Required Input Parameters
array
The list of items to output: a Collection (Vector, List, or Set), Iterator, Enumeration, Map, Dictionary, or array.
numColumns
The number of columns used to display the array.
Optional Input Parameters
sortProperties
A string that specifies the order to render array items. The syntax of this parameter depends on the array item type: JavaBean, Dynamic Bean, Date, Number, or String.
To sort on the properties of a JavaBean, specify the value of sortProperties
as a comma-separated list of property names. You can sort on an unlimited number of properties, where the first property name specifies the primary sort, the second property name specifies the secondary sort, and so on. Prepend the property name with a plus +
or minus -
sign in order to specify ascending or descending sort order.
For example, the following input parameter specifies to sort an array of JavaBeans alphabetically by title , then in descending order of size
:
<dsp:param name="sortProperties" value="+title,
size"/>
If an array consists of Dates, Numbers, or Strings, prepend the sortProperties
value with a plus +
or minus –
sign to specify ascending or descending sort order.
The following example sorts an output array of Strings in alphabetical order:
<dsp:param name="sortProperties" value="+"/>
In order to sort Map elements by key, set the value as follows:
{+|-}_key
For example:
<dsp:param name="sortProperties" value="
_key"/>
A nested servlet bean inherits the parent servlet bean’s sortProperties
setting, unless the nested servlet bean has its own sortProperties
setting. For example, the following setting negates any parent sortProperties
setting:
<dsp:param name="sortProperties" value=""/>
Output Parameters
index
Set to the zero-based index of the current array element each time the output
parameter is rendered.
count
Set to the one-based index of the current array element each time the output
parameter is rendered. The value of count
for the first iteration is 1.
rowIndex
Set to the current row index each time an output parameter is rendered.
columnIndex
Set to the current column index each time an output parameter is rendered.
key
If the array
parameter is a Map or Dictionary, set to the Map or Dictionary key.
element
Set to the current array element each time the output
parameter is rendered. If the array size is not an even multiple of the number of columns, element
is set to null for the remaining items in the last row.
Open Parameters
output
Rendered once for each array element .
outputStart
If the array is not empty, rendered before any output elements. For example, this parameter can be used to render the table heading.
outputEnd
If the array is not empty, rendered after all output elements. For example, this parameter can be used to render text following a table.
outputRowStart
If the array is not empty, rendered once for each row in the output at the beginning of the row. For example, this parameter can be used to render the row heading of a table.
outputRowEnd
If the array is not empty, rendered once for each row in the output at the end of the row. For example, this parameter can be used to render text following a row in a table.
empty
Rendered if the array contains no elements.
Usage Notes
TableForEach is an extension of the servlet beanForEach. TableForEach renders its output
parameter in a two-dimensional format, such as a table. The array
parameter can be a Collection (Vector, List, or Set), Iterator, Enumeration, Map, Dictionary, or array. The numColumns
parameter specifies the number of columns across which to display the array. The elements of the array are arranged across the columns.
The output
parameter is rendered for each cell in the table. If the array size is not a multiple of the number of columns, output
is rendered with a null element parameter for the remaining columns in the last row. A Switch servlet bean can be used to conditionally fill in the missing items in the row.
Example
The following example displays the values of the initialServices
property of the ATG platform’s Initial
component. The values are displayed in a two-column table. The outputStart
, outputEnd
, outputRowStart
, and outputRowEnd
open parameters define the table formatting.
<dsp:importbean bean="/atg/dynamo/droplet/TableForEach"/> <dsp:droplet name="TableForEach"> <dsp:param bean="/Initial.initialServices" name="array"/> <dsp:param name="numColumns" value="2"/> <dsp:oparam name="outputStart"><table border=1></dsp:oparam> <dsp:oparam name="outputEnd"></table></dsp:oparam> <dsp:oparam name="outputRowStart"><tr></dsp:oparam> <dsp:oparam name="outputRowEnd"></tr></dsp:oparam> <dsp:oparam name="output"> <td> <dsp:valueof param="element.absoluteName"> </dsp:valueof> </td> </dsp:oparam> </dsp:droplet>