You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Michael Forster <fo...@fmi.uni-passau.de> on 2002/06/30 21:10:29 UTC

[JSTL] Length of a list

Hi,
   
is there a way in JSTL to get the length of a java.util.List?
   
Mike
   

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [JSTL] Length of a list

Posted by Shawn Bayern <ba...@essentially.net>.
On Sun, 30 Jun 2002, Michael Forster wrote:

> is there a way in JSTL to get the length of a java.util.List?

Not easily, unfortunately.  This functionality will be added in JSP 2.0.  
In the meantime, you can wrap the List in an object that returns both the
List and the count:

  getList() { return l; }
  getSize() { return l.size(); }

If you want to use *just* JSTL, you can loop over the List with
<c:forEach> and set a variable equal to the count:

  <c:forEach items="${myList}" varStatus="s">
    <c:if test="${s.last}">
      <c:set var="count" value="${s.count}"/>
    </c:if>
  </c:forEach>

but this is obviously not ideal; it is, however, a clever workaround.

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com
(coming in July 2002 from Manning Publications)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>