This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes What is other way to iterate throgh collection instead of logic:iterate...? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "What is other way to iterate throgh collection instead of logic:iterate...?" Watch "What is other way to iterate throgh collection instead of logic:iterate...?" New topic
Author

What is other way to iterate throgh collection instead of logic:iterate...?

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
Hi,
In my application I want to display array of records into the html table having 5 columns. Out of five columns 3 columns are taking values from one collection (say partsdata[]) & other two columns are taking values from second collection(say orderdata[]). At any time both collections will have same size. How should I display records from both collection simultaneously into my table in JSP file?
Is there any other way to iterate through collections other than <logic:iterate...?
that is, like:- <bean:write name="orderForm" property="partsdata[0].partno"/> & so on...
Please reply.
Thank you.
Prash


********Deserve Before You Desire********
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You're on the right track. If you are sure the length of the arrays will always be the same, you can iterate over one array and use the same index for both arrays:

<logic:iterate id="part" name="orderForm" property="partsData" indexId="i">
<bean:write name="orderForm" property='<%=partsData["+i+"]".partno%>' />
<bean:write name="orderForm" property='<%=orderData["+i+"]".orderno%>' />
</logic:iterate>

The above code assumes you have indexed getters and setters for both partsData and orderData.


Merrill
Consultant, Sima Solutions
Dhulipalla
Greenhorn

Joined: Aug 02, 2006
Posts: 4
Then your problem will be answered if you use an opensource tag called displaytag

http://displaytag.sourceforge.net/11/
Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
Hi,
I saw the link you provided to me http://displaytag.sourceforge.net
& also I downloaded displaytag1.1.jar from site. Now I copied thhis jar into my web-inf/lib directory of my web project. I am using STRUTS1.1 for my web development. What are the additional changes I need to do so as to work display tags for my web application. I tried by simply writeing following Taglib header into my JSP page:-
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>

But when I am running my jsp page , it gives me error like:-
java.lang.NoClassDefFoundError: org/apache/commons/lang/UnhandledException
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:2328)
java.lang.Class.getConstructor0(Class.java:2640)
java.lang.Class.newInstance0(Class.java:321)
java.lang.Class.newInstance(Class.java:303)

So how to solve it?

Please help me.
thank you.
Prash
 
 
subject: What is other way to iterate throgh collection instead of logic:iterate...?