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 Help In displaying properties of objects contained in ArrayList 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 "Help In displaying properties of objects contained in ArrayList" Watch "Help In displaying properties of objects contained in ArrayList" New topic
Author

Help In displaying properties of objects contained in ArrayList

Vinod Dalal
Greenhorn

Joined: Mar 23, 2006
Posts: 3
Hi,

I have a problem iterating over an arrayList which contains list of objects. I want to print all of the properties of the objects.

Here is the scenario:

I have a class SampleObj with properties say sample1, sample1, sample3

public SampleClass{

private String sample1;
private String sample2;
private String sample3;

...getter and setter methods..

}


Now in an ActionForm class reset method I set these properties and put them in to an ArrayList

public SampleActionForm extends ActionForm{

private ArrayList sampleList;

reset(..){
SampleClass obj;
while(some Condition){
obj=new SampleClass();
obj.setSample1(...);
obj.setSample2(..);
obj.setSample3(..);

sampleList.add(obj);
/* adding obj to the array List. At the end of loop this ArrayList holds some objects */

}

}

}

Now in the JSP I need to display the properties of the objects contained in ArrayList. Here is the expected out put

obj1.sample1 obj1.sample2 obj1.sample3
obj2.sample1 obj2.sample2 obj2.sample3
.............. ................ ...............

Also this out put goes in side <html:form action="...."> so the form bean is also available


I tried <logic:iterate> and <nested:iterate> but because of my limited knowledge in these tags I could not get the desired output. Can some one help me with this?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since this appears to be a learning exercise, I won't give you the answer outright, but I will try to point you in the right direction.

Readthis link, paying particular attention to the section entitled "Dynamic Indexes for Indexed Properties".

If after reading this, you're still unable to figure it out, let us know and we'll help.


Merrill
Consultant, Sima Solutions
Vinod Dalal
Greenhorn

Joined: Mar 23, 2006
Posts: 3
Hi Merrill

Thanks for the link. I figured out how I can do that.
 
 
subject: Help In displaying properties of objects contained in ArrayList
 
Similar Threads
passing parameters to a method.
Fresh SDK Install Won't Compile?
servlets and xml
confusion in if condition
returning comparison counter from collections.sort()