Sunday 27 January 2013

Check a collection size with JSTL

Leave a Comment

length( java.lang.Object) - Returns the number of items in a collection, or the number of characters in a string.
put this at the top of the page to allow the fn namespace
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
and use like this in your jsp page
<p>The length of the companies collection is : ${fn:length(companies)}</p>
(from memory)
So to test with length of a collection:
<c:if test="${fn:length(companies) gt 0}">
   <p>It is greater than 0</p>
</c:if>

0 comments:

Post a Comment