Forums Register Login

Getting values from a map in JSTL

+Pie Number of slices to send: Send
Howdy!
I spent a lot of time with this problem: I have map of values in the request, I'm iterating over another collection and I want to get values from the map with keys I got from the collection.
Something like:
<c:forEach items="${myCollection}" value="elem" >
<c:out value="${myMap[elem.key]}" />
</c:forEach>
but no way 'myMap[elem.key]' doesn't work!
I've tried various combinations, without luck.
(finally I did it by iterating over the map and comparing the key, but that should be the map's work!)
Somebody saw something like this?
+Pie Number of slices to send: Send
"It doesn't work" is not a useful description of the problem.

Your syntax is fine. Have you verified that the map is really in the request? Have you verified that elem.key contains what you expect on each iteration?
+Pie Number of slices to send: Send
At least I'm glad the sintax seems fine
I gave up when I reached the point where I had:
<c:set var="aKey" value="<some key I know is in the map>" />
<c:out value="${aKey == elem.key} /> <-- result: true
<c:out value="${myMap[aKey]}" /> <--- result: the value I expected
<c:out value="${myMap[elem.key]}" /> <--- result: empty!!

I'll keep experimenting, because I'm quite puzzled...
This tiny ad is wafer thin:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 27179 times.
Similar Threads
EL mapEntry.value prints Ljava.lang.String@
Iterating over Map using JSTL
Struts 2 iterate over a Map
c:forEach in JSTL
Accessing a HashMap using Struts 2
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:42:08.