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 <[EMAIL PROTECTED]> 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