I asked this question a little while ago, and the answer was quite
useful....I have copied the text of those emails below...email me if you
need more help...
keith
>From: "Keith Morrell" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>Subject: Iterate over a bean full of beans?
>Date: Mon, 23 Apr 2001 17:12:57 +1200
>
>I have an issue where I want to iterate using a bean which has
"child"
>beans (excuse the non-industry standard lingo!) and would appreciate
>some advice (sorry this is my third post today, but I have been
>struggling with this and a couple of other issues for days now..)
>
>The old code went something like:
>
><% Iterator it = Summary.getAccounts().iterator();
> if(it.hasNext())....
>
>... and then within this loop,
>
><% while( it.hasNext() )
>{
> AccountBean ab = (AccountBean) it.next();
> out.println( ab.getName();
> out.println( ab.getPhone();
>
>... etc...
>
>Any help etc would be appreciated...as i am not sure how to access
the
>child bean properties etc from the main bean (which would control the
>iterate loop)
>
Here is what I am doing :
I have a Bean with a vector field...
public class SearchResult implements Serializable {
private Vector lots = new Vector();
... and a method returning an array of the vector's elements ...
public Lot[] getLots() {
Lot[] results = new Lot[lots.size()];
lots.copyInto(results);
return results;
}
In the JSP I can use the iterate tag as follow :
<logic:iterate id="lot" name="searchResult" property="lots">
...
<bean:write name="lot" property="number" filter="true"/>
...
</logic:iterate>
Hope this helps
Gael Laurans
______________________________
as far as i know you can have nested iterate tags:
<logic:iterate id="outerObj" name="beanX" property="OuterCollection">
<bean:write name="outerObj" property="name/>
<logic:iterate id="innerObj" name="outerObj"
property="InnerCollection">
<bean:write name="innerObj" property="name"/>
</logic:iterate>
</logic:iterate>
i think the trick is referencing the page scope var you've created
in the outer iterate... in this case "outerObj".
chris
At 09:42 PM 4/23/2001 +0700, Gael Laurans wrote:
>>From: "Keith Morrell" <[EMAIL PROTECTED]>
>>Reply-To: [EMAIL PROTECTED]
>>To: [EMAIL PROTECTED]
>>Subject: Iterate over a bean full of beans?
>>Date: Mon, 23 Apr 2001 17:12:57 +1200
>>
>>I have an issue where I want to iterate using a bean which has
"child"
>>beans (excuse the non-industry standard lingo!) and would appreciate
>>some advice (sorry this is my third post today, but I have been
>>struggling with this and a couple of other issues for days now..)
>>
>>The old code went something like:
>>
>><% Iterator it = Summary.getAccounts().iterator();
>> if(it.hasNext())....
>>
>>... and then within this loop,
>>
>><% while( it.hasNext() )
>>{
>> AccountBean ab = (AccountBean) it.next();
>> out.println( ab.getName();
>> out.println( ab.getPhone();
>>
>>... etc...
>>
>>Any help etc would be appreciated...as i am not sure how to access
the
>>child bean properties etc from the main bean (which would control
the
>>iterate loop)
>Here is what I am doing :
>I have a Bean with a vector field...
>
> public class SearchResult implements Serializable {
> private Vector lots = new Vector();
>
>... and a method returning an array of the vector's elements ...
>
> public Lot[] getLots() {
> Lot[] results = new Lot[lots.size()];
> lots.copyInto(results);
> return results;
> }
>
>In the JSP I can use the iterate tag as follow :
>
> <logic:iterate id="lot" name="searchResult" property="lots">
> ...
> <bean:write name="lot" property="number" filter="true"/>
> ...
> </logic:iterate>
>
>Hope this helps
>Gael Laurans
>_________________________________________________________________________
>Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.
>___________________________________________
Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.
Please note new extension number/s below...
Keith Morrell
EDS Consultant, TRAID Project
Phone +64-9-308-5650
EDS internal extn 4150
>From Telecom PABX 84150
Fax +64-9-309-8543
Cell +64-21-649-395
Email T906399 (internal) or [EMAIL PROTECTED]