Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help on How to Iterate Multiple List in JSP

 
Piyush Balas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 3 Arraylist built in Java action, List1, List2 and List3.

I am using Struts2 and want to iterate all 3 list at a same time in JSP so can anyone suggest a way on how to do that?

My requirement is

List1 contains Name for exa{AA,BB,CC...}
List2 contains Technology names {Java, JSP, Net...}
List3 contains Expertise {1,2,3,...}

My output will be in JSP should like

Name Technology Expertise
----------------------------------------
AA Java 1
BB JSP 2
CC Net 3

Can anyone help me please?

Thanks in advance.

Piyush
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have such a poor model for your data? If each of these properties describe an element, you should have a bean that abstracts the element. Then you would have one list of the beans, each of which holds the three properties for whatever is being modeled.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush,
Welcome to CodeRanch!

As Bear points out, you should create a Java object. Then you can use a Struts tag or JSTL to loop through that single list.
 
Piyush Balas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for quick response.

Do you have such example which i can refer?


Thanks
Piyush
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, it looks like each item (whatever they are) has a name, a technology, and a numeric level of some sort. Rather than three lists that contains these values separately, define a class that groups them together logically to describe the item. Without more information, I'll simply call the item a zarb. And the Zarb class could be:

Then you have one list of zarbs that gets passed to the JSP for iteration with <c:forEach> (or whatever the heck Struts uses).

The job of a JSP gets infinitely harder when you model data poorly.
 
Piyush Balas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for your help.


Piyush
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic