{"id":75,"date":"2013-06-28T13:10:13","date_gmt":"2013-06-28T13:10:13","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=75"},"modified":"2013-06-28T14:15:28","modified_gmt":"2013-06-28T14:15:28","slug":"how-to-iterate-through-bean-map-list-struts2","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-to-iterate-through-bean-map-list-struts2\/","title":{"rendered":"How to iterate through Bean Map List Struts2"},"content":{"rendered":"<p><strong>Running Iterator Through Bean Stored in Map List<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class Iterator extends ActionSupport\r\n{\r\n   Map nmap = new HashMap&lt;String, List&lt;Person&gt;&gt;();\r\n\t\r\n   public String execute()\r\n   {\r\n      Person objPerson    = new Person();\r\n\r\n      objPerson.userName  = &quot;Name1&quot;;\r\n      objPerson.age \t    = 25;\r\n      List&lt;Person&gt; myList = new ArrayList&lt;Person&gt;();\r\n      myList.add(objPerson);\r\n\t\t\r\n      nmap.put(&quot;Mugil&quot;, myList);\r\n\t\r\n      objPerson.userName   = &quot;Name2&quot;;\r\n      objPerson.age \t     = 26;\r\n      List&lt;Person&gt; myList2 = new ArrayList&lt;Person&gt;();\r\n      myList2.add(objPerson);\r\n\t\t\r\n      nmap.put(&quot;Mani&quot;, myList2);\r\n\t\t\r\n      objPerson.userName    = &quot;Name3&quot;;\r\n      objPerson.age \t      = 27;\r\n      List&lt;Person&gt; myList3  = new ArrayList&lt;Person&gt;();\r\n      myList3.add(objPerson);\r\n\t\t\r\n      nmap.put(&quot;Vinu&quot;, myList3);\r\n\t\t\r\n      setNmap(nmap);\r\n\t\t\r\n      return SUCCESS;\r\n   }\r\n\t\r\n   public Map getNmap() \r\n   {\r\n     return nmap;\r\n   }\r\n\r\n   public void setNmap(Map nmap) \r\n   {\r\n     this.nmap = nmap;\r\n   }\r\n}\r\n<\/pre>\n<p><strong>Person Bean Code<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass Person\r\n{\r\n    String userName;\r\n    int age;\r\n\r\n    public int getAge() {\r\n      return age;\r\n    }\r\n\r\n    public void setAge(int age) {\r\n      this.age = age;\r\n    }\r\n\r\n    public String getUserName() {\r\n      return userName;\r\n    }\r\n\t\r\n    public void setUserName(String userName) {\r\n      this.userName = userName;\r\n    }\r\n}\r\n<\/pre>\n<p><strong>JSP Page Using Struts2 Tag<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;table&gt;\r\n&lt;s:iterator value=&quot;nmap&quot;&gt;\r\n     &lt;s:iterator var=&quot;Person&quot; value=&quot;value&quot;&gt;\r\n      &lt;tr&gt;\r\n     \t&lt;td&gt;\r\n    \t  &lt;s:property value=&quot;key&quot; \/&gt;\t\r\n    \t&lt;\/td&gt;\r\n        &lt;td&gt;\r\n      \t  &lt;s:property value=&quot;age&quot; \/&gt;\r\n    \t&lt;\/td&gt;\r\n      &lt;\/tr&gt;\r\n      &lt;\/s:iterator&gt;\r\n&lt;\/s:iterator&gt;\r\n&lt;\/table&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Running Iterator Through Bean Stored in Map List public class Iterator extends ActionSupport { Map nmap = new HashMap&lt;String, List&lt;Person&gt;&gt;(); public String execute() { Person objPerson = new Person(); objPerson.userName = &quot;Name1&quot;; objPerson.age = 25; List&lt;Person&gt; myList = new ArrayList&lt;Person&gt;(); myList.add(objPerson); nmap.put(&quot;Mugil&quot;, myList); objPerson.userName = &quot;Name2&quot;; objPerson.age = 26; List&lt;Person&gt; myList2 = new ArrayList&lt;Person&gt;(); myList2.add(objPerson);&hellip; <a href=\"https:\/\/codethataint.com\/blog\/how-to-iterate-through-bean-map-list-struts2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-iteration"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":7,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/75\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}