You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jamesey <Ja...@hotmail.com> on 2003/03/12 15:52:21 UTC
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?
Question2 how do you set up the iterate tag to get both values?
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: logic:iterate.. newbie question
Posted by Jamesey <Ja...@hotmail.com>.
thanks very much.. thats a great help..
"James Mitchell" <jm...@apache.org> wrote in message
news:002801c2e8ac$45c0aff0$6f01a8c0@atlanta...
> Not exactly, if you had an ArrayList of String, you could don't need
> property.
> Like this:
>
> <%
> ArrayList lst = new ArrayList();
> lst.add("value 1");
> lst.add("value 2");
> lst.add("value 3");
> request.setAttribute("myCollection", lst);
> %>
>
> <logic:iterate id="itm" name="myCollection">
> <bean:write name="itm"/><br>
> </logic:iterate>
>
> --
> James Mitchell
> Software Developer/Struts Evangelist
> http://struts.sourceforge.net/struts-atlanta/
>
>
>
> > -----Original Message-----
> > From: Jamesey [mailto:JamesPrance@hotmail.com]
> > Sent: Wednesday, March 12, 2003 10:18 AM
> > To: struts-user@jakarta.apache.org
> > Subject: Re: logic:iterate.. newbie question
> >
> >
> > that helps massively.. and confirms my own deductions...
> >
> > and i'm assuming if i use an array of objects the name
> > property changed to
> > reflect the setAttribute name
> >
> > "James Mitchell" <jm...@apache.org> wrote in message
> > news:002001c2e8a9$e5fd6060$6f01a8c0@atlanta...
> > > > -----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
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: logic:iterate.. newbie question
Posted by James Mitchell <jm...@apache.org>.
Not exactly, if you had an ArrayList of String, you could don't need
property.
Like this:
<%
ArrayList lst = new ArrayList();
lst.add("value 1");
lst.add("value 2");
lst.add("value 3");
request.setAttribute("myCollection", lst);
%>
<logic:iterate id="itm" name="myCollection">
<bean:write name="itm"/><br>
</logic:iterate>
--
James Mitchell
Software Developer/Struts Evangelist
http://struts.sourceforge.net/struts-atlanta/
> -----Original Message-----
> From: Jamesey [mailto:JamesPrance@hotmail.com]
> Sent: Wednesday, March 12, 2003 10:18 AM
> To: struts-user@jakarta.apache.org
> Subject: Re: logic:iterate.. newbie question
>
>
> that helps massively.. and confirms my own deductions...
>
> and i'm assuming if i use an array of objects the name
> property changed to
> reflect the setAttribute name
>
> "James Mitchell" <jm...@apache.org> wrote in message
> news:002001c2e8a9$e5fd6060$6f01a8c0@atlanta...
> > > -----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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: logic:iterate.. newbie question
Posted by Jamesey <Ja...@hotmail.com>.
that helps massively.. and confirms my own deductions...
and i'm assuming if i use an array of objects the name property changed to
reflect the setAttribute name
"James Mitchell" <jm...@apache.org> wrote in message
news:002001c2e8a9$e5fd6060$6f01a8c0@atlanta...
> > -----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
RE: logic:iterate.. newbie question
Posted by James Mitchell <jm...@apache.org>.
> -----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