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. Notice that you have to use EL expression to specify the collection.
<listbox> <zscript> grades = new String[] {"Best", "Better", "Good"}; </zscript> <listitem label="${each}" forEach="${grades}"/> </listbox>
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>