I tried the following which surprisingly does not work, looks like .values does not work at all in jstl:
<c:forEach var="r" items="${applicationScope['theMap'].values}">
The map is defined like this (and later saved to the ServletContext):
Map<Integer, CustomObject> theMap = new LinkedHashMap<Integer, CustomObject>();
How to get this working? I actually really would like to avoid modifying what's inside of the foreach-loop.
So you want to iterate over map values?
Map
doesn't have agetValues()
method, so your attempt doesn't work. The<c:forEach>
gives aMap.Entry
back on every iteration which in turn hasgetKey()
andgetValue()
methods. So the following should do:Since EL 2.2, with the new support for invoking non-getter methods, you could just invoke
Map#values()
directly:See also:
Map
using<c:forEach>
?Also you can use this type if necessary
you can iterate a map in jstl like following