struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Mitchell" <jmitch...@apache.org>
Subject RE: logic:iterate.. newbie question
Date Wed, 12 Mar 2003 15:13:11 GMT
> -----Original Message-----
> From: Jamesey [mailto:JamesPrance@hotmail.com] 
> Sent: Wednesday, March 12, 2003 9:52 AM
> To: struts-user@jakarta.apache.org
> 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
> object..so 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:
MyBean
 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"/>
</logic:iterate>


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().


HTH

--
James Mitchell
Software Developer/Struts Evangelist
http://struts.sourceforge.net/struts-atlanta/


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


Mime
View raw message