Size of collection in a JSP/DSP page
by Frank Kim on May.15, 2008, under JSTL, Page Development, Struts
Sometimes in a JSP/DSP page you will want to get the size of a collection and unless you are within a Range, ForEach or similar droplet you won’t have access to this value.
Struts has a nice solution using the " href="http://struts.apache.org/1.3.8/struts-taglib/tagreference.html#size">" href="http://struts.apache.org/1.3.8/struts-taglib/tagreference.html#size">" href="http://struts.apache.org/1.3.8/struts-taglib/tagreference.html#size"><bean:size> tag. JSTL 1.1 has a nice solution using the fn:length function.
Here is an example of how to use Struts, DSPEL and JSTL to get the size of a collection.
<dspel:getvalueof param="book.pages" var="pages"
vartype="java.util.Collection"/>
<bean:size id="numPages" name="pages"/>
Number of Pages: <c:out value="${numPages}"/>
Number of Pages: <dspel:valueof value="${numPages}"/>
Here is an example of how to use JSTL 1.1 and DSPEL to get the size of a collection.
<dspel:getvalueof param="book.pages" var="pages"
vartype="java.util.Collection"/>
Number of Pages: <c:out value="${fn:length(pages)}"/>
Related posts:
