0

HI,

I need to be able to do something like this (of course this doesn't work:

  <c:forEach var="column" items="${model.${listName}.enabledColumns}">
    ${column.name}
  </c:forEach>

Thanks

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
goe
  • 25
  • 2

2 Answers2

3

Use brackets:

${requestScope[listName].eanbledColumns}

or, if your model is actually a map within the request, then:

${model[listName].enabledColumns}
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

If the ${listName} in this context is a property of your model (something you would normally access as model.getListNameX(), this would only be possible with reflection, and the Expression Language has no support for that.

But it looks like a refactoring of your class would be more helpful. If you want to iterate through those ${listName}s (assuming these are currently properties of your model) , why don't you just keep a map with enum constants as keys and those objects you want to reference via ${listName} as values ? (an EnumMap would be helpful here).

Then, you can set the Enum.values() as a request attribute, iterate through them as listName and have:

${model.lists[listName].enabledColumns}
Costi Ciudatu
  • 37,042
  • 7
  • 56
  • 92