开发者

Accessing Map attribute with dynamic key in Struts 2 OGNL

开发者 https://www.devze.com 2023-02-11 03:13 出处:网络
I have a list of Strings that are attribute names an开发者_开发技巧d a Map. I\'m trying to access a model(ex.project) in the map using attribute name in string list.

I have a list of Strings that are attribute names an开发者_开发技巧d 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号