Panasonic Youth rob sanheim writes about software, business, ruby, music, stuff and things



Posted
17 January 2006 @ 2pm

Tagged
Java

Discuss

Getting size of collection in JSTL 1.0

Assuming JSTL 1.0, this doesn’t work:

<c:out value="${myMap.size}" />

and neither does this

<c:set var="mapSize" value="${myMap.size}" />
<c: out value=”${mapSize}” />

I’m assuming JSTL wants to find something called getSize()…
So is this the only way to do it?

<%=((java.util.Map) pageContext.findAttribute("myMap")).size() %>

(meta note: if I actually get all the HTML escape codes right for this, I will be amazed)


4 Comments

Posted by
Maik
17 January 2006 @ 3pm

Short answer: It’s the only way.

Short answer #2: Use JSTL 1.1 and fn:length().


Posted by
Rob
17 January 2006 @ 3pm

Maik: thats what I was afraid of. Thanks.


Posted by
Martin van den Bemt
18 January 2006 @ 5am

If you used jsp:useBean you can also do


Posted by
Martin van den Bemt
18 January 2006 @ 5am

If you used jsp:useBean you can also do
myMap.size() instead of ((java.util.Map) pageContext.findAttribute(”myMap”)).size()


Leave a Comment

Public Radio Fan Naming test objects - mock, stub, fake?