Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the size of a HashMap using jstl

Tags:

java

jsp

jstl

Is there any way to get the size of a Map using JSTL ? I tried with ${myMap.size} but it's not working..

like image 591
coder247 Avatar asked Jan 31 '11 13:01

coder247


3 Answers

got the solution: Use jstl functions.

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

then use like this:

  <c:if test="${fn:length(myMap) > 1 }">
like image 146
coder247 Avatar answered Oct 12 '22 20:10

coder247


${myMap.size}

isn't working because it gets translated to myMap.getSize() by the EL parser.

Try:

${myMap.size()}

It should work.

like image 24
The-MeLLeR Avatar answered Oct 12 '22 22:10

The-MeLLeR


The JSTL length function works on a Collection but not sure if it will work on a Map. Might be worth a try.

like image 25
Qwerky Avatar answered Oct 12 '22 22:10

Qwerky