Dynamator Pure HTML for every page generation technology.

This set of examples shows how to iterate over the contents of collections. In HTML, collections are usually output using a element specifically designed to support repetition (li, option, tr, or dt/dd). Dynamator allows any HTML element to be repeated for iteration. Dynamator can generate code to support any JDK 1.1 or 1.2 collection: array, Vector, Enumeration, Dictionary, Properties, Iterator, and Map. This tutorial covers only JDK 1.1 collections.

Iteration is accomplished by adding a 'foreach' element to the Dynamator entry for an id or class value. In the 'foreach' element, you can specify attributes that identify the type of the collection and the name of each Java variable that needs to be generated to support iteration. Most of the time, such fine-grained control is not needed. In this tutorial, we will be demonstrating use of only the required attributes. For complete information about the syntax of the 'foreach' element in Dynamator for JSP, see the man page for Dynamator Language Support for JSP.

The 'foreach' element has two required attributes:

type The type of the collection. This may be one of the following:
Type[] The collection is an array of elements of type Type. Both objects and primitives are supported.
Vector[Type] The collection is a Vector of elements of type Type.
Enumeration[Type] The collection is an Enumeration of elements of type Type.
Iterator[Type] The collection is an Iterator over elements of type Type.
Dictionary[KeyType,ValueType] The collection is a Dictionary. Keys in the dictionary are of type KeyType, and values are of type ValueType.
Map[KeyType,ValueType] The collection is a Map. Keys in the map are of type KeyType, and values are of type ValueType.
Properties The collection is a Properties container.
element The name of the variable that references the current element.


Example 9a: Creating a Dynamically Populated List
How to iterate over elements of arrays, Vectors, and Enumerations.
Example 9b: Creating a Dynamically Populated Choice List
How to iterate over a list of element choices, and how to obtain the offset of the current element while iterating.
Example 9c: Creating Dynamically Populated Table Rows
How to iterate over a sequence of objects.
Example 9d: Creating Dynamically Populated Dictionary Lists
How to iterate over a dictionary or properties collection.