Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Map attribute with dynamic key in Struts 2 OGNL

I have a list of Strings that are attribute names and a Map. I'm trying to access a model(ex.project) in the map using attribute name in string list.

Here is what I have now.

<s:iterator value="theMap" var="element">
  <tr>
    <s:iterator value="attributeList" var="attrName">
      <td><p><s:property value="#element.Project.#attrName" /></p></td>
    </s:iterator>
  </tr>
</s:iterator>

If I hard code the attribute name it works fine:

<td><p><s:property value="#element.Project.projectName" /></p></td>

Any advice is appreciated.

like image 902
Daniel Kim Avatar asked Feb 18 '11 15:02

Daniel Kim


1 Answers

Using OGNL <s:property value="#element.Project[#attrName]" />

like image 113
Aleksandr M Avatar answered Sep 25 '22 00:09

Aleksandr M