Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help In displaying properties of objects contained in ArrayList

 
Vinod Dalal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vinod Dalal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill

Thanks for the link. I figured out how I can do that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic