I would like to pass Multiple parameters for single param in action t开发者_StackOverflow社区ag.
Ex:
<action name="question" class="com.xxx.xxx.action">
<param name="hint">abc</param>
<result name="success">Answers.jsp</result>
</action>
I have getters and setters for hint (String) variable in my action.
Currently i can be able to get parameter value for hint variable as abc if i send one.
I would like to send multiple parameters for same variable(hint)
ex: <param name="hint">abc, xyz</param>
how can achieve the above.
Thanks in advance Raju
I found the best answer here (look at the bottom of the page):
http://www.coderanch.com/t/494764/Struts/define-String-array-param-tag
If for some reason the link is broken, here is what you do:
<s:param name="queryType" value="new java.lang.String[]{'PRIMARY','SECONDARY'}"/>
If you are submitting a <s:form>
, you just use the same NAME for multiple parameters and Struts2 automatically creates the String Array!
Just remember to create the correct setter and getter in your action, for example:
public void setQueryType(String[] queryType){
this.queryType = queryType;
}
Notice that you declare String[ ] as an Array, that's all!
I don't think you can do that, apart from the obvious hacks For example, just write the above in you mapping and in your action convert the string to a array
String[] getHintsArray() {
return getParam("hint").split("\\s*,\\s*");
}
精彩评论