File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:forEach

 
Mel Calvin
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code:

ArrayList list1 = new ArrayList();
ArrayList list2 = new ArrayList();
ArrayList list3 = new ArrayList();
list1.add(0, "list1-row1");
list1.add(1, "list1-row2");
list1.add(2, "list1-row3");
list2.add(0, "list2-row1");
...
list3.add(2, "list3-row3"):

HashMap map = new HashMap();
map.put("List1", list1);
map.put("List2", list2);
map.put("List3", list3);
request.setAtttribute("MAP", map);
forwarding to the jsp-page...

If I in a jsp-page wanted to print out the first rows the three arrays, how could that be achieved? I.e. retrieve only one element per iteration per array. I just can't get this to work..

Regards,
Mel.
[ September 17, 2007: Message edited by: Bear Bibeault ]
 
Amol Nayak
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we have three Lists bound to request scope with names list1, list2 and list3 and assuming that all three lists have same size we can do this.



If you really want to use HashMap and this logic to be generic then i would recommend you to write a tag and implement the logic in the tag class.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not clear what you are trying to achieve. What do you mean by "retrieve only one element per iteration per array"?

By nature, only one element will be retrieved per iteration so I'm not sure what's "special" about what you are trying to do?
 
Mel Calvin
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a hashmap of arrays, if I iterate over the map and prints the elements, it will print the arrays as a whole. I want to print the elements of the arrays which is not that easy, however, I have come oup with a solution:


This code works..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic