struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Samere, Adam J" <asam...@paychex.com>
Subject RE: iterating over multiple Collections in one loop with JSTL
Date Thu, 25 May 2006 16:18:27 GMT
How about creating a single list with an object to encapsulate the
values from list1 and list2 in a single entity?

Public class MyClassContainer {
	private MyClass1 my1;
	private MyClass2 my2;

	...
} 

List<MyClassContainer> = ...

myClassContainerList.add(new MyClassContainer(myClass1, myClass2));

Then in the JSP you only need one loop.

<c:forEach var="myContainer" items="myContainerList">
	<c:set var="myClass1" value="${myContainer.my1}"/>
	<c:set var="myClass2" value="${myContainer.my2}"/>
	...
</c:forEach>

Adam

-----Original Message-----
From: Pat Slater [mailto:pslater33@yahoo.com] 
Sent: Thursday, May 25, 2006 11:28 AM
To: user@struts.apache.org
Subject: iterating over multiple Collections in one loop with JSTL

Hi,
Is it possible to do with JSTL something like this: 
(Note: size of list1 and list2 are equal) List list1 = getList1(); List
list2 = getList2(); for(int i=0; i<list1.size(); i++) {
    MyClass1 x1 = (MyClass1)list1.get( i );
    MyClass2 x2 = (MyClass2)list2.get( i ); }
------------------------------------------------------------------------
----
I can iterate with JSTL with forEach for either of the lists separately
but I need to display both of them in the same loop. How can I do that?


			
---------------------------------
Sneak preview the  all-new Yahoo.com. It's not radically different. Just
radically better. 

-----------------------------------------
The information contained in this message may be privileged,
confidential, and protected from disclosure. If the reader of this
message is not the intended recipient, or any employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any dissemination, distribution, or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify us immediately
by replying to the message and deleting it from your computer.

Thank you. Paychex, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message