This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Need Help on How to Iterate Multiple List in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Need Help on How to Iterate Multiple List in JSP" Watch "Need Help on How to Iterate Multiple List in JSP" New topic
Author

Need Help on How to Iterate Multiple List in JSP

Piyush Balas
Greenhorn

Joined: May 18, 2013
Posts: 3
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

Joined: Jan 10, 2002
Posts: 60752
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Piyush Balas
Greenhorn

Joined: May 18, 2013
Posts: 3
Thanks Bear for quick response.

Do you have such example which i can refer?


Thanks
Piyush
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

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

Joined: May 18, 2013
Posts: 3
Thanks Bear for your help.


Piyush
 
jQuery in Action, 2nd edition
 
subject: Need Help on How to Iterate Multiple List in JSP
 
Similar Threads
Problem with SELECT_COMMAND in List
Find matches in two collections
c:forEach
How to get Full Form Id?
jsp tags inside javascript function