Oracle Fusion Middleware Tag Reference for Oracle ADF Faces
11g Release 1 (11.1.1.6.0)

E12419-08

<af:forEach>

forEach for each


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" when used with deferred evaluation. 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 ADF af: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>: <af:forEach> does not currently support arbitrary java.util.Collections; it can only iterate over java.util.Lists or arrays.

Caution

The forEach tag should be used with intent and knowledge. The forEach tag is not used in JSF for iteration, but instead for generating multiple components. If your goal is to iterate over a collection of objects and render HTML for each item, <af:iterator> should be using instead.

Instances when <af:forEach> would be needed instead of <af:iterator>:

Example:


            <af:selectOneListbox value="#{someValue}">
              <af:forEach var="item" items="#{model.listOfItems}">
                <af:selectItem value="#{item.value}" text="#{item.text}"/>
              </af:forEach>
            </af:selectOneListbox>

            <af:forEach varStatus="vs" begin="1" end="5">
              <af:outputText id="ot2" value="#{vs.index} #{vs.count} #{vs.begin}"/>
            </af:forEach>

Attributes

Name Type Supports EL? Description
begin int No index at which iteration begins
end int No index at which iteration ends
items Object Only EL the collection to iterate over
step int No number to increment on each iteration
var String No name of the variable exposed when iterating
varStatus String No name of the loop status exposed when iterating. The properties 'index','count','begin','end','step','first','last' are available through this