struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Mitchell" <>
Subject RE: logic:iterate.. newbie question
Date Wed, 12 Mar 2003 15:13:11 GMT
> -----Original Message-----
> From: Jamesey [] 
> Sent: Wednesday, March 12, 2003 9:52 AM
> To:
> Subject: logic:iterate.. newbie question
> I have and array or collection of objects (the object has two 
> members with
> appropriate getter and setters)
> i want to iterate through the array and retrieve each value for the
> it will look like this
> value a  valueb
> value a  valueb
> value a  valueb
> Question1. does the iteration object HAVE to be a bean? cant 
> it just be an
> array of objects?

No.  You could use an array of String or ArrayList of Integer, whatever.
The logic:iterate will look slightly different though.

> Question2 how do you set up the iterate tag to get both values?

You'll need to write them out using bean:write

If you have a collection of bean:
 String valueA;
 String valueB; 
 (with getters and setters)

Then you can display them as follows:

(in your action)
  //setup your collection
  //then add to request
request.setAttribute("myCollectionOfMyBean", coll);
  // then forward to your jsp

(in your jsp)
<logic:iterate id="itm" name="myCollectionOfMyBean">
 <bean:write name="itm" property="valueA"/>
 <bean:write name="itm" property="valueB"/>

See, the logic:iterate sets up a scripting variable named 'itm' so that
the bean:write tag can use it to call getValueA() and getValueB().


James Mitchell
Software Developer/Struts Evangelist

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message