• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL + forEach + Map problem

 
Jordi Monn�
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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� ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!