Struts 2 List Parameter Passing
How do I pass a list of integers using the s:a href and param tags in Struts 2?
Example POJO:
private List<Integer> myList = new ArrayList<Integer>();
public List<Integer> getMyList() {
return myList;
}
public void setMyList(List<Integer> myList) {
this.myList = myList;
}
Example JSP Page:
<s:url id="testUrl" action="testAction">
<s:param name="myList" value="%{myList}" />
</s:url>
<s:a href="%{testUrl}">Test Link</s:a>
When I click on the "Test Link", the form submits the following for myList:
开发者_StackOverflow[1,+2,+3,+4,+5]
This results in Struts re-directing to the "input" page. This is not the desired behavior. Does anyone have any suggestions about how to pass a list of integers correctly using the Struts tags?
The param tag calls the toString on the list to put the parameter in the URL if I remember right. Therefore the action that should get the list only gets a string.
The setter on the next action needs to accept a string and in this setter you could split up the string, extract the numbers and fill a new list with that.
精彩评论