aspose file tools*
The moose likes Struts and the fly likes I need help, with logic:iterate in HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "I need help, with logic:iterate in HashMap" Watch "I need help, with logic:iterate in HashMap" New topic
Author

I need help, with logic:iterate in HashMap

Jose Larico
Greenhorn

Joined: Nov 25, 2003
Posts: 1
I would like to do a ITERATE in a jsp page. For this I have been using a HashMap and each element of this map contains an ArrayList. In the array list different objects are stocked. I would lilke to recuperate each ArrayList and make it de second iterate. Ex.
ArrayList liste = new ArrayList();
UnObject o1 = new UnObject();
o1.setId(1);
o1.setSubject("Some text 1");
liste.add(o);
UnObject o2 = new UnObject();
o2.setId(2);
o2.setSubject("Some text 2");
liste.add(o2);
java.util.HashMap h = new java.util.HashMap();
h.put("MyID",liste);
request.setAttribute("myIterate",h);
<logic:iterate id="ref" name="myIterate">
.....
.....
</logic:iterate>
Thank...
Uwe Barthel
Greenhorn

Joined: Dec 16, 2003
Posts: 9
Originally posted by Jose Larico:
I would like to do a ITERATE in a jsp page. For this I have been using a HashMap and each element of this map contains an ArrayList. In the array list different objects are stocked. I would lilke to recuperate each ArrayList and make it de second iterate. Ex.
ArrayList liste = new ArrayList();
UnObject o1 = new UnObject();
o1.setId(1);
o1.setSubject("Some text 1");
liste.add(o);
UnObject o2 = new UnObject();
o2.setId(2);
o2.setSubject("Some text 2");
liste.add(o2);
java.util.HashMap h = new java.util.HashMap();
h.put("MyID",liste);
request.setAttribute("myIterate",h);
<logic:iterate id="ref" name="myIterate">
.....
.....
</logic:iterate>
Thank...

Ok, take a look into the documentation of the struts logic tag.
http://jakarta.apache.org/struts/userGuide/struts-logic.html
-----8<----------8<----------8<-----
...
Normally, each object exposed by the ITERATE TAG is an element of the underlaying collection you are iterating over. However, if you iterate over a Map, the exposed object is of type Map.Entry that has two properties:
  • key - The key under which this item is stored in the underlaying Map
  • value - The value that corresponds to this key.

  • So, if you wish to iterate over the values of a Hashmap, you would implement code like the following:

    ...
    -----8<----------8<----------8<-----
    So, hope that helps
    Uwe Barthel


    --<br />Sorry for my bad englich
    sha ram
    Greenhorn

    Joined: Nov 25, 2003
    Posts: 12
    Is there a nested logic iterate tag? If so, Please give me an example.
    sha ram
    Greenhorn

    Joined: Nov 25, 2003
    Posts: 12
    Try this....
    <%
    ArrayList liste = new ArrayList();
    liste.add("apple");
    liste.add("grapes");
    java.util.HashMap h = new java.util.HashMap();
    h.put("MyID",liste);
    request.setAttribute("attr",h);
    %>
    <logic:iterate id="it" name="attr">
    <logic:iterate name="it" property="value" id="order">
    <bean:write name="order" />
    </logic:iterate>
    </logic:iterate>
     
     
    subject: I need help, with logic:iterate in HashMap