Search code examples
javajspstruts2ognl

s:iterator over Map with a dynamic key parameter


I have a problem with the inner iterator in the following Struts2 JSP:

<s:iterator value="thatCompany.tags" var="tagGroups">
  <tr>
     <td><s:property value="#tagGroups.key" /></td><!-- this works nicely! -->
     <td>
    <ul>
     <s:iterator value="{thisCompany.tags['#tagGroups.key']}" var="thisTagGroup">
           <!-- doesn't work, displays one empty LI element -->
           <li> <s:property value="#thisTagGroup.key"/>
      </s:iterator>
    </ul>
      </td>
<!-- snip -->

thisCompany.tags and thatCompany.tags are both of type Map<String, Map<BigDecimal, String>>


Solution

  • Got it, this syntax works:

    <s:iterator value="thisCompany.tags[#tagGroups.key]" var="foobar">
      <li> <s:property value="#foobar.value"/>
    </s:iterator>
    

    But this is weird: if I name the variable thisTagGroup instead of foobar it doesn't work anymore. Is it because this is somehow reserved and variable names cannot even begin with this-?