Single Page


Iterative Evaluation

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.

<listbox>
<listitem label="${each}" forEach="grades"/>
</listbox>