The Java EE 5 Tutorial

Flow Control Tags

The XML flow control tags parallel the behavior described in Flow Control Tags for XML data streams.

The JSP page tut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookcatalog.jsp uses the forEach tag to display all the books contained in booklist as follows:

<x:forEach var="book"
     select="$applicationScope:booklist/books/*">
    <tr>
        <c:set var="bookId">
            <x:out select="$book/@id"/>
        </c:set>=
        <td bgcolor="#ffffaa">
             <c:url var="url"
            value="/bookdetails" >
                <c:param name="bookId" value="${bookId}" />
                <c:param name="Clear" value="0" />
            </c:url>
            <a href="${url}">
            <strong><x:out select="$book/title"/>&nbsp;
            </strong></a></td>
         <td bgcolor="#ffffaa" rowspan=2>
             <c:set var="price">
                <x:out select="$book/price"/>
            </c:set>
            <fmt:formatNumber value="${price}" type="currency"/>
             &nbsp;
        </td>
         <td bgcolor="#ffffaa" rowspan=2>
         <c:url var="url" value="/catalog" >
            <c:param name="Add" value="${bookId}" />
        </c:url>
         <p><strong><a href="${url}">&nbsp;
            <fmt:message key="CartAdd"/>&nbsp;</a>
        </td>
    </tr>
     <tr>
         <td bgcolor="#ffffff">
         &nbsp;&nbsp;<fmt:message key="By"/> <em>
            <x:out select="$book/firstname"/>&nbsp;
            <x:out select="$book/surname"/></em></td></tr>
</x:forEach>