Home > JSF, Mini-tips > Get collection (set,list,map) size in JSF view (xhtml)

Get collection (set,list,map) size in JSF view (xhtml)

When I started with JSF  I needed to know the size of certain list, and the natural thinking was… well Im gonna try #{bean.myAwesomeList.size} of course it is not going to work, so… after this I met the JSTL Functions Library and tadaaaaa!! problem solved, I used the fn:length which gives you the size of any Collections or the length of a String, and it goes something like this:

Step 1:  Include in your html the xmlns of this library

    ...here goes all your namespaces...  
    xmlns:fn="http://java.sun.com/jsp/jstl/functions" />

Step 2:  Show the magic!

   value="My collection size: #{fn:length(bean.myList)} Dang thats huge!" />
Categories: JSF, Mini-tips
  1. Anonymous
    December 3, 2012 at 12:58


    • Anonymous
      December 3, 2012 at 13:00


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: