8.4.12 forEach
8.4.12.1 Kinds of loops
8.4.12.1.1 Counting loops
<t:forEach begin="1" end="5" step="2"> <p>do something</p> </t:forEach>
8.4.12.1.2 Iterating loops
<t:forEach var="item" in="${mylist}" [begin="1"] [end="5"] [step="2"]>
<p>do something with ${item}</p>
</t:forEach>
8.4.12.2 Supported list types
You can loop over:
- Java arrays
- any kind of Java Collection
- org.w3c.dom.NodeList and org.w3c.dom.Node (will iterate over the child nodes)
- any other kind of object will behave as a single-entry list
8.4.12.3 Loop status
Inside the forEach, you have access to a variable called loopStatus providing the following fields:
- position: the current value between begin and end, augmented with the step upon each loop
- index: sequence number augmented upon each loop, starting from 0
- number: same as index, but starting from 1
- revIndex, revNumber [todo see issue #111]
Previous