Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting values from a map in JSTL

 
Gabriel Claramunt
Ranch Hand
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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?
 
Gabriel Claramunt
Ranch Hand
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic