Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Getting values from a map in JSTL

 
Ranch Hand
Posts: 376
Scala Monad
  • 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" >
<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?
 
Marshal
Posts: 67416
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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: 376
Scala Monad
  • 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>" />
<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...
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic