tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wendy Smoak <j...@wendysmoak.com>
Subject Re: c:forEach & index in looop
Date Wed, 27 Jul 2005 21:53:54 GMT
From: "Marco Mistroni" <mmistroni@gmail.com>
> i am trying to replace struts logic:iterate with  JSTL c:forEach...
> however,  i need what in logic:iterate is the index in the loop
> is it possible to get it from anywhere?

Section 6.1.3 and 6.4 of the JSTL 1.0 specification talk about the
'varStatus' attribute of <c:forEach> and how to use it to get not only the
index, but the count, and whether or not this is the first or last element
(useful for delimited lists when you don't want the extra delimiter at the
end).

   http://www.jcp.org/aboutJava/communityprocess/final/jsr052/

<c:forEach items="${myList}" var="item" varStatus="status">
    <c:out value="item"/> -
    <c:out value="${status.index}"/>,
    <c:out value="${status.count}"/>,
    <c:out value="${status.first}"/>,
    <c:out value="${status.last}"/><br/>
</c:forEach>

-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message