You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ezequiel Puig <e....@vivacances.fr> on 2007/06/06 17:09:01 UTC

RE : [s2] Collection, array and tag.

Musachy,

Thanks a lot for the comments about the <s:url> tag.

About the other questions i proposed, do you know if it's possible to manipulate arrays with the s2 tags ??




-----Message d'origine-----
De : Musachy Barroso [mailto:musachy@gmail.com] 
Envoyé : mercredi 6 juin 2007 16:41
À : Struts Users Mailing List
Objet : Re: [s2] Collection, array and <s:url> tag.

I logged this ticket for it:

https://issues.apache.org/struts/browse/WW-1971

musachy

On 6/6/07, Musachy Barroso <mu...@gmail.com> wrote:
>
> Looking at the code, only String[] is transformed into parameters. For
> anything else, its toString() will be called and used as the value of the
> parameter.
>
> I think  Lists and Sets should be processed as String[] are (calling the
> toString() on each element). Maps should be converted to parameters using
> the key (toString() of the key element) as the name of the parameter and the
> value (toString() of the value) as the value of course.
>
>
> //I used to think that you could use an iterator tag inside a url tag, but
> that doesn't work
>
> musachy
>
> On 6/6/07, Ezequiel Puig < e.puiz@vivacances.fr> wrote:
> >
> > Hi,
> >
> >
> >
> > I have been using struts 2 since a while and there is some things about
> > the <s:url> tag i don't understant.
> >
> >
> >
> > Let's say we have an array in our action (with the getters and setters):
> >
> >
> >
> >     private String[] myArray;
> >
> >
> >
> >     public String[] getMyArray() {
> >
> >         return myArray;
> >
> >     }
> >
> >     public void setMyArray(String[] myArray) {
> >
> >         this.myArray = myArray;
> >
> >     }
> >
> >
> >
> > and that in our action, we do something to initializate the array:
> >
> >
> >
> >     String[] arr = new String[3];
> >
> >     arr[0] = "Aa";
> >
> >     arr[1] = "Bb";
> >
> >     arr[2] = "Cc";
> >
> >
> >
> > Now, if in our JSP we use the <s:url> tag:
> >
> >
> >
> > <a href="<s:url includeParams="none" action="TestUrlArray.action ">
> >
> >                     <s:param name="myArray" value="myArray" />
> >
> >              </s:url>" >Use Link
> >
> > </a>
> >
> >
> >
> > we can see that the created url is:
> >
> >
> >
> > TestUrlArray.action?myArray=Aa&myArray=Bb&myArray=Cc
> >
> >
> >
> > Also, in the destination action, we are able to recover the information
> > from the variable "myArray" if we have defined something like "private
> > String[] myArray".
> >
> >
> >
> > So for, so good.
> >
> >
> >
> > Now, let's see the Collections:
> >
> >
> >
> > In the action we will have:
> >
> >
> >
> >     private Collection<String> myCollection = new ArrayList<String>();
> >
> >
> >
> >     public Collection <String> getMyCollection () {
> >
> >         return myCollection;
> >
> >     }
> >
> >     public void setMyList(Collection <String> myCollection) {
> >
> >         this.myCollection = myCollection;
> >
> >     }
> >
> >
> >
> > we initialize the collection:
> >
> >
> >
> >     Collection<String> col = new ArrayList<String>();
> >
> >     col.add("Aa");
> >
> >     col.add("Bb");
> >
> >     col.add("Cc");
> >
> >     setMyCollection(col);
> >
> >
> >
> > Finally, we use the <s:url> tag:
> >
> >
> >
> > <a href="<s:url includeParams="none" action=" TestUrlArray.action ">
> >
> >                     <s:param name="myCollection" value="myCollection" />
> >
> >              </s:url>" >Use Link
> >
> > </a>
> >
> >
> >
> > Here, the created link looks like:
> > TestUrlArray.action?myCollection=[Aa,+Bb,+Cc]
> >
> >
> >
> > But, if we try to recover the collection in the destination action
> > (where offcourse we have defined "Collection<String> col = new
> > ArrayList<String>();" ), we will see that we recover a collection of
> > only one element, and that this element is our old collection (the one
> > with 3 elements).
> >
> >
> >
> > Now, it's time for questions:
> >
> >
> >
> > 1)       Is it possible to manipulate arrays with the s2 tags ? (by
> > manipulate, i mean create a new array, add an element to an existing
> > array, remove an element, etc.)
> >
> > 2)       Is it possible to manipulate collections with the s2 tags ?
> > (same meaning to manipulate)
> >
> > 3)       Is there a work-arround to recover a Collection not as a new
> > collection of one element that contains a collection but as a new
> > collection that is like the collection we passed ?
> >
> >
> >
> >
> >
> > Well, any ideas will be reallly wellcome :-)
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd




-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: RE : [s2] Collection, array and tag.

Posted by Dave Newton <ne...@yahoo.com>.
--- Zoran Avtarovski <zo...@sparecreative.com> wrote:
> For example on a search form we would add a not
> applicable object to the start of our collection. 

> <html:select property="image">
>     <html:option value="-1">No Image</html:option>
>     <html:optionsCollection name="fileList"
>         label="fileName"
>         value="fileName"/>
> </html:select>
> 
> I'd love to be able to do something similar in S2,

<s:select headerKey="-1" headerValue="No Image" .../>

d.



 
____________________________________________________________________________________
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 

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


Re: RE : [s2] Collection, array and tag.

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
I can give you a simple use case we have which annoys the crap out of me:

In S1 we used our business layer to get a collection of objects. Depending
on how that collection was used we might need to add an object to it. For
example on a search form we would add a not applicable object to the start
of our collection. This would allow to see if that parameter should be used
in the search. Or another example is when getting a list of images from the
file system and you want to give the user the option for no image. This is
how we do this in S1:

<html:select property="image">
    <html:option value="-1">No Image</html:option>
    <html:optionsCollection name="fileList" label="fileName"
value="fileName"/>
</html:select>

I'd love to be able to do something similar in S2, but instead we have had
to write support methods in view support classes to implement it.

The OGNL Language guide says its possible but I'm having trouble getting it
to work.

Z.

> Maybe there is some OGNL trick, but I wouldn't know how. Are you sure you
> want to change manipulate arrays in your pages (view)? Maybe there is a
> valid use case for it, but it sounds weird to me.
> 
> musachy
> 
> On 6/6/07, Ezequiel Puig <e....@vivacances.fr> wrote:
>> 
>> Musachy,
>> 
>> Thanks a lot for the comments about the <s:url> tag.
>> 
>> About the other questions i proposed, do you know if it's possible to
>> manipulate arrays with the s2 tags ??
>> 
>> 
>> 
>> 




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


Re: RE : [s2] Collection, array and tag.

Posted by Musachy Barroso <mu...@gmail.com>.
Maybe there is some OGNL trick, but I wouldn't know how. Are you sure you
want to change manipulate arrays in your pages (view)? Maybe there is a
valid use case for it, but it sounds weird to me.

musachy

On 6/6/07, Ezequiel Puig <e....@vivacances.fr> wrote:
>
> Musachy,
>
> Thanks a lot for the comments about the <s:url> tag.
>
> About the other questions i proposed, do you know if it's possible to
> manipulate arrays with the s2 tags ??
>
>
>
>
> -----Message d'origine-----
> De: Musachy Barroso [mailto:musachy@gmail.com]
> Envoyé: mercredi 6 juin 2007 16:41
> À: Struts Users Mailing List
> Objet: Re: [s2] Collection, array and <s:url> tag.
>
> I logged this ticket for it:
>
> https://issues.apache.org/struts/browse/WW-1971
>
> musachy
>
> On 6/6/07, Musachy Barroso <mu...@gmail.com> wrote:
> >
> > Looking at the code, only String[] is transformed into parameters. For
> > anything else, its toString() will be called and used as the value of
> the
> > parameter.
> >
> > I think  Lists and Sets should be processed as String[] are (calling the
> > toString() on each element). Maps should be converted to parameters
> using
> > the key (toString() of the key element) as the name of the parameter and
> the
> > value (toString() of the value) as the value of course.
> >
> >
> > //I used to think that you could use an iterator tag inside a url tag,
> but
> > that doesn't work
> >
> > musachy
> >
> > On 6/6/07, Ezequiel Puig < e.puiz@vivacances.fr> wrote:
> > >
> > > Hi,
> > >
> > >
> > >
> > > I have been using struts 2 since a while and there is some things
> about
> > > the <s:url> tag i don't understant.
> > >
> > >
> > >
> > > Let's say we have an array in our action (with the getters and
> setters):
> > >
> > >
> > >
> > >     private String[] myArray;
> > >
> > >
> > >
> > >     public String[] getMyArray() {
> > >
> > >         return myArray;
> > >
> > >     }
> > >
> > >     public void setMyArray(String[] myArray) {
> > >
> > >         this.myArray = myArray;
> > >
> > >     }
> > >
> > >
> > >
> > > and that in our action, we do something to initializate the array:
> > >
> > >
> > >
> > >     String[] arr = new String[3];
> > >
> > >     arr[0] = "Aa";
> > >
> > >     arr[1] = "Bb";
> > >
> > >     arr[2] = "Cc";
> > >
> > >
> > >
> > > Now, if in our JSP we use the <s:url> tag:
> > >
> > >
> > >
> > > <a href="<s:url includeParams="none" action="TestUrlArray.action ">
> > >
> > >                     <s:param name="myArray" value="myArray" />
> > >
> > >              </s:url>" >Use Link
> > >
> > > </a>
> > >
> > >
> > >
> > > we can see that the created url is:
> > >
> > >
> > >
> > > TestUrlArray.action?myArray=Aa&myArray=Bb&myArray=Cc
> > >
> > >
> > >
> > > Also, in the destination action, we are able to recover the
> information
> > > from the variable "myArray" if we have defined something like "private
> > > String[] myArray".
> > >
> > >
> > >
> > > So for, so good.
> > >
> > >
> > >
> > > Now, let's see the Collections:
> > >
> > >
> > >
> > > In the action we will have:
> > >
> > >
> > >
> > >     private Collection<String> myCollection = new ArrayList<String>();
> > >
> > >
> > >
> > >     public Collection <String> getMyCollection () {
> > >
> > >         return myCollection;
> > >
> > >     }
> > >
> > >     public void setMyList(Collection <String> myCollection) {
> > >
> > >         this.myCollection = myCollection;
> > >
> > >     }
> > >
> > >
> > >
> > > we initialize the collection:
> > >
> > >
> > >
> > >     Collection<String> col = new ArrayList<String>();
> > >
> > >     col.add("Aa");
> > >
> > >     col.add("Bb");
> > >
> > >     col.add("Cc");
> > >
> > >     setMyCollection(col);
> > >
> > >
> > >
> > > Finally, we use the <s:url> tag:
> > >
> > >
> > >
> > > <a href="<s:url includeParams="none" action=" TestUrlArray.action ">
> > >
> > >                     <s:param name="myCollection" value="myCollection"
> />
> > >
> > >              </s:url>" >Use Link
> > >
> > > </a>
> > >
> > >
> > >
> > > Here, the created link looks like:
> > > TestUrlArray.action?myCollection=[Aa,+Bb,+Cc]
> > >
> > >
> > >
> > > But, if we try to recover the collection in the destination action
> > > (where offcourse we have defined "Collection<String> col = new
> > > ArrayList<String>();" ), we will see that we recover a collection of
> > > only one element, and that this element is our old collection (the one
> > > with 3 elements).
> > >
> > >
> > >
> > > Now, it's time for questions:
> > >
> > >
> > >
> > > 1)       Is it possible to manipulate arrays with the s2 tags ? (by
> > > manipulate, i mean create a new array, add an element to an existing
> > > array, remove an element, etc.)
> > >
> > > 2)       Is it possible to manipulate collections with the s2 tags ?
> > > (same meaning to manipulate)
> > >
> > > 3)       Is there a work-arround to recover a Collection not as a new
> > > collection of one element that contains a collection but as a new
> > > collection that is like the collection we passed ?
> > >
> > >
> > >
> > >
> > >
> > > Well, any ideas will be reallly wellcome :-)
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > --
> > "Hey you! Would you help me to carry the stone?" Pink Floyd
>
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd