betweenGo

Size of collection in a JSP/DSP page

by Frank Kim on May.15, 2008, under JSTL, Page Development, Struts

leaf pile on Flickr

(Photo: leaf pile by oeimah)

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)}"/>


  • Share/Bookmark

Related posts:

  1. Trim White Space from JSP
  2. ATG ForEach Output with Separators Between Items
  3. Jumping to different parts of a page using a dropdown
  4. Accessing RepositoryItems with JSTL
  5. Comparison of DSP and DSPEL

:, , , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!