This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Getting values from a map in JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting values from a map in JSTL" Watch "Getting values from a map in JSTL" New topic
Author

Getting values from a map in JSTL

Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
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" >
<cut 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?


Gabriel
Software Surgeon
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

"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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
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>" />
<cut value="${aKey == elem.key} /> <-- result: true
<cut value="${myMap[aKey]}" /> <--- result: the value I expected
<cut value="${myMap[elem.key]}" /> <--- result: empty!!

I'll keep experimenting, because I'm quite puzzled...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting values from a map in JSTL
 
Similar Threads
Iterating over Map using JSTL
Struts 2 iterate over a Map
EL mapEntry.value prints Ljava.lang.String@
c:forEach in JSTL
Accessing a HashMap using Struts 2