Search code examples
javajspstrutsjsp-tagsstruts-tags

How to iterate over Map<String, List<MyObject>> in the jsp using struts tag library?


On Backend side I have a Map:

SortedMap<String, List<MyObject>> myMap = new TreeMap<>()

MyObject has private String name field with pulic getter and setter

On jsp I have:

<nested:iterate property="myMap" id="map">
     <bean:write name="map" property="key"/>
      <nested:iterate property="listElement" id="value">
          <bean:write name="value" property="name"/>
      </nested:iterate>
</nested:iterate>

But I see error:

Caused by: javax.servlet.jsp.JspException: No getter method for property: "otherBean.MyMap(API).listElement" of bean: "MyBeanForm"

How could I fix it ?


Solution

  • It works

    <nested:iterate property="myMap" id="entry">
         <bean:write name="entry" property="key"/>
          <nested:iterate property="value" name="entry" id="obj">
              <bean:write name="obj" property="name"/>
          </nested:iterate>
    </nested:iterate>