Project Documentation

Summary

Tag name: <tr:forEach>

The forEach tag is a replacement for the JSTL <c:forEach> tag. Though as of JSF 1.2/JSP 2.1/JSTL 1.2, <c:forEach> can be used with any JSF components or tags, it does not support "varStatus". This tag adds support for varStatus (other than "current" which is not supported). (Note: this tag is not supported in Facelets, because c:forEach is fully functional in Facelets.) Unlike the old Trinidad tr:forEach built with JSF 1.1, however, this tag can be used with any JSP 2.1-based tag, JSF or non-JSF. This tag also has a limitation not found in <c:forEach>: <tr:forEach> does not currently support arbitrary java.util.Collections; it can only iterate over java.util.Lists or arrays.

Example:

            <tr:selectOneListbox value="#{someValue}">
              <tr:forEach var="item" items="#{model.listOfItems}">
                <tr:selectItem value="#{item.value}" text="#{item.text}"/>
              </tr:forEach>
            </tr:selectOneListbox>
            <tr:forEach varStatus="vs" begin="1" end="5">
              <tr:outputText id="ot2" value="#{vs.index} #{vs.count} #{vs.begin} #{vs.current}"/>
            </tr:forEach>

Attributes

Name Type Supports EL? Description
beginintNo index at which iteration begins
endintNo index at which iteration ends
itemsObjectOnly EL the collection to iterate over
stepintNo number to increment on each iteration
varStringNo name of the variable exposed when iterating
varStatusStringNo name of the loop status exposed when iterating. The properties 'index','count','begin','end','step','first','last' are available through this