Running Iterator Through Bean Stored in Map List

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class Iterator extends ActionSupport
{
   Map nmap = new HashMap<String, List<Person>>();
   
   public String execute()
   {
      Person objPerson    = new Person();
 
      objPerson.userName  = "Name1";
      objPerson.age       = 25;
      List<Person> myList = new ArrayList<Person>();
      myList.add(objPerson);
     
      nmap.put("Mugil", myList);
   
      objPerson.userName   = "Name2";
      objPerson.age        = 26;
      List<Person> myList2 = new ArrayList<Person>();
      myList2.add(objPerson);
     
      nmap.put("Mani", myList2);
     
      objPerson.userName    = "Name3";
      objPerson.age         = 27;
      List<Person> myList3  = new ArrayList<Person>();
      myList3.add(objPerson);
     
      nmap.put("Vinu", myList3);
     
      setNmap(nmap);
     
      return SUCCESS;
   }
   
   public Map getNmap()
   {
     return nmap;
   }
 
   public void setNmap(Map nmap)
   {
     this.nmap = nmap;
   }
}

Person Bean Code

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
class Person
{
    String userName;
    int age;
 
    public int getAge() {
      return age;
    }
 
    public void setAge(int age) {
      this.age = age;
    }
 
    public String getUserName() {
      return userName;
    }
   
    public void setUserName(String userName) {
      this.userName = userName;
    }
}

JSP Page Using Struts2 Tag

01
02
03
04
05
06
07
08
09
10
11
12
13
14
<table>
<s:iterator value="nmap">
     <s:iterator var="Person" value="value">
      <tr>
      <td>
        <s:property value="key" /> 
      </td>
        <td>
          <s:property value="age" />
      </td>
      </tr>
      </s:iterator>
</s:iterator>
</table>