The evaluation of an element could be iterative. By specifying a collection of objects to the forEach Attribute, developers could control how many time of the associated element shall be evaluated. For sake of description, we call an element is an iterative element if it is assigned with the forEach attribute.
In the following example, the list item is created three times. Each of them has the label called "Best", "Better" and "God", respectively.
<listbox>
<listitem label="${each}" forEach="Best, Better, God"/>
</listbox>
If you have a variable holding a collection of objects, then you can specify it directly in the forEach attribute. For example, assume you have a variable called grades as follows.
grades = new String[] {"Best", "Better", "Good"};
Then, you can iterate them by use of the forEach attribute as follows. Notice that you have to use EL expression to specify the collection.
<listbox>
<listitem label="${each}" forEach="${grades}"/>
</listitem>
The iteration depends on the type of the specified value of the forEach attribute.
If java.util.Collection, it iterates each element of the collection.
If java.util.Map, it iterates each Map.Entry of the map.
If java.util.Iterator, it iterates each element from the iterator.
If java.util.Enumeration, it iterates each element from the enumeration.
If Object[], int[], short[], byte[], char[], float[] or double[] is specified, it iterates each element from the array.
If null, nothing is generated (it is ignored).
If neither of above types is specified, the associated element will be evaluated once as if a collection with a single item is specified.
<listbox>
<listitem label="${each}" forEach="grades"/>
</listbox>