Access to Map attribute with dynamic key in Struts 2 OGNL

I have a list of strings that are attribute names and Map. I am trying to access a model (ex.project) on a map using the attribute name in the list of strings.

Here is what I have.

<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 hardcode the attribute name, it works fine:

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

Any advice is appreciated.

+7
source share
1 answer

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

+4
source

All Articles