• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

JSTL + forEach + Map problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have a Map<String,List>. To get the value from a Map I know that I have to do ${map["key"}].

My problem is that I have to do that inside a forEach where each key is a variable.

Example:

<c:forEach var="i" items="${parents}">
${child[${i.id}]]}
</c:forEach>

It doesn't work. Any advices?

Thanks in advance
[ August 24, 2006: Message edited by: Jordi Monn� ]
 
Sheriff
Posts: 67561
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First things first. Do you have a copy of the JSP spec handy? If so, be sure to read the chapter on the EL. If not, you're doing it wrong. Everyone writing JSPs should have read the spec.

Your fundamental misunderstanding with the EL is that the ${} notation is not a "fetch" operator. It encloses the entire EL expression, so your notation with it nested:

${child[${i.id}]]}

makes absolutely no sense.

${child[i.id]}

will fetch the property or map entry for child for whatever i.id evaluates to.
 
reply
    Bookmark Topic Watch Topic
  • New Topic