Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

I need help, with logic:iterate in HashMap

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
     
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Is there a nested logic iterate tag? If so, Please give me an example.
     
    sha ram
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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>
     
    WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic