You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Sundar @eSaravana" <su...@eSaravana.com> on 2001/03/23 19:12:29 UTC

Iterate Tag question, again --> Short ane sweet

Since nobody seemed to have read my long mail, I am re-writing my mail short
and probably sweet.

Can I do, multilevel iteration with iterate tag.?
For example:
I have collection of beans in my session. In my JSP, I want to first iterate
at the collection to get the individual beans. And for every bean again
iterate to get attributes/variables.

Any help is deeply appreciated.

Cheers.......................!
Sundar


Re: Iterate Tag question, again --> Short ane sweet

Posted by Cecil Pang <cp...@10dt.com>.
How about using the tag

<bean:define id="secondCollection" name="elementFromFirstColleciton" 
property="someCollecitonProperty" scope="session"/>

to get a handle on the second collection and then literate on 
"secondCollection"


At 11:12 AM 3/23/2001 -0700, you wrote:
>Since nobody seemed to have read my long mail, I am re-writing my mail short
>and probably sweet.
>
>Can I do, multilevel iteration with iterate tag.?
>For example:
>I have collection of beans in my session. In my JSP, I want to first iterate
>at the collection to get the individual beans. And for every bean again
>iterate to get attributes/variables.
>
>Any help is deeply appreciated.
>
>Cheers.......................!
>Sundar



Re: Iterate Tag question, again --> Short ane sweet

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sat, 24 Mar 2001, Sundar @eSaravana wrote:

> Hi,
> 
> This is my situation:
> I have a collection(Vector) of buddyListForm as session attribute.
> 
> So, in my JSP,
> 
> <logic:iterate id="buddylist" property="buddylist" scope="session"> <!--
> vector being iterated -->

If the Vector you are storing is under session key "buddyListForm", this
should really say something like:

<logic:iterate id="buddy" name="buddylist" scope="session">

> <!--Now, I have the individual bean, how do I iterate the properties-->
> <logic:iterate  id="buddy" name="buddylist" scope="session">
> <tr>
>     <bean:write name= "buddy"  property="name" filter="true"/>
> </tr>
> </logic:iterate>
> </logic:iterate>
> 

There was a bug several months ago where the "id" bean was not getting
exposed correctly, but that has been fixed.  How old is the version of
Struts you are using?

> All I get for this code is:
> javax.servlet.jsp.JspException: Cannot find bean buddy in scope null
> 	at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:212)
> 	at
> org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:............
> .....
> 
> I am attaching buddyListForm, too.
> 
> Sundar
> 

Craig



Re: Iterate Tag question, again --> Short ane sweet

Posted by "Sundar @eSaravana" <su...@eSaravana.com>.
Hi,

This is my situation:
I have a collection(Vector) of buddyListForm as session attribute.

So, in my JSP,

<logic:iterate id="buddylist" property="buddylist" scope="session"> <!--
vector being iterated -->
<!--Now, I have the individual bean, how do I iterate the properties-->
<logic:iterate  id="buddy" name="buddylist" scope="session">
<tr>
    <bean:write name= "buddy"  property="name" filter="true"/>
</tr>
</logic:iterate>
</logic:iterate>

All I get for this code is:
javax.servlet.jsp.JspException: Cannot find bean buddy in scope null
	at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:212)
	at
org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:............
.....

I am attaching buddyListForm, too.

Sundar


----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: <st...@jakarta.apache.org>
Cc: <st...@jakarta.apache.org>
Sent: Friday, March 23, 2001 2:41 PM
Subject: Re: Iterate Tag question, again --> Short ane sweet


>
>
> On Fri, 23 Mar 2001, Sundar @eSaravana wrote:
>
> > Since nobody seemed to have read my long mail, I am re-writing my mail
short
> > and probably sweet.
> >
> > Can I do, multilevel iteration with iterate tag.?
> > For example:
> > I have collection of beans in my session. In my JSP, I want to first
iterate
> > at the collection to get the individual beans. And for every bean again
> > iterate to get attributes/variables.
>
> There is no current mechanism to iterate over the properties of a bean
> (which is what I *think* you meant by attributes/variables).  However, if
> your bean had a method that returned all the interesting stuff as a Map or
> something like that, you could certainly have a nested iteration over
> that.
>
> For example, consider a bean that has a getter method:
>
> public Map getProperties();
>
> and you had a collection of them called "beans".  Then you can:
>
> <logic:iterate id="bean" name="beans">
>   Now processing bean <bean:write name="bean" property="id"/>
>   <logic:iterate id="property" name="bean" property="properties">
>     Property <bean:write name="property" property="key"/>
>     has value <bean:write name="property" property="value"/>
>   </logic:iterate>
> </logic:iterate>
>
>
> > Any help is deeply appreciated.
> >
> > Cheers.......................!
> > Sundar
> >
> >
>
> Craig
>
>

Re: Iterate Tag question, again --> Short ane sweet

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 23 Mar 2001, Sundar @eSaravana wrote:

> Since nobody seemed to have read my long mail, I am re-writing my mail short
> and probably sweet.
> 
> Can I do, multilevel iteration with iterate tag.?
> For example:
> I have collection of beans in my session. In my JSP, I want to first iterate
> at the collection to get the individual beans. And for every bean again
> iterate to get attributes/variables.

There is no current mechanism to iterate over the properties of a bean
(which is what I *think* you meant by attributes/variables).  However, if
your bean had a method that returned all the interesting stuff as a Map or
something like that, you could certainly have a nested iteration over
that.

For example, consider a bean that has a getter method:

	public Map getProperties();

and you had a collection of them called "beans".  Then you can:

<logic:iterate id="bean" name="beans">
  Now processing bean <bean:write name="bean" property="id"/>
  <logic:iterate id="property" name="bean" property="properties">
    Property <bean:write name="property" property="key"/>
    has value <bean:write name="property" property="value"/>
  </logic:iterate>
</logic:iterate>    


> Any help is deeply appreciated.
> 
> Cheers.......................!
> Sundar
> 
> 

Craig



Re: Iterate Tag question, again --> Short ane sweet

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 23 Mar 2001, Sundar @eSaravana wrote:

> Since nobody seemed to have read my long mail, I am re-writing my mail short
> and probably sweet.
> 
> Can I do, multilevel iteration with iterate tag.?
> For example:
> I have collection of beans in my session. In my JSP, I want to first iterate
> at the collection to get the individual beans. And for every bean again
> iterate to get attributes/variables.

There is no current mechanism to iterate over the properties of a bean
(which is what I *think* you meant by attributes/variables).  However, if
your bean had a method that returned all the interesting stuff as a Map or
something like that, you could certainly have a nested iteration over
that.

For example, consider a bean that has a getter method:

	public Map getProperties();

and you had a collection of them called "beans".  Then you can:

<logic:iterate id="bean" name="beans">
  Now processing bean <bean:write name="bean" property="id"/>
  <logic:iterate id="property" name="bean" property="properties">
    Property <bean:write name="property" property="key"/>
    has value <bean:write name="property" property="value"/>
  </logic:iterate>
</logic:iterate>    


> Any help is deeply appreciated.
> 
> Cheers.......................!
> Sundar
> 
> 

Craig