" />
开发者

passing in a list of strings to a jsf bean

In my JSF file, I have a command button that looks like this:

'< h:commandButton value="Start." action='#{myBean.startIt}'/>

startIt() is a method with no arguments that has a hardcoded ArrayList of Strings.

What I would really like to do is pass in a variable number of Strings to startIt(), and get rid of the hardcoding.

If I try the "vararg" syntax, e.g.

public void startIt(String... myStrings){ ...}

I get the following error when I call the function with a even a single string:

wrong number of argumentswrong number of arguments class java.lang.IllegalArgumentException

Any ideas on how to get varargs to work with JSF 2, or failing that, another solution to the underlying problem w开发者_运维问答ould be most appreciated.

Thanks.


One of the ways you can do this by specifying value in the f:param element and then reterving that value in backing bean:

<h:commandLink actionListener="#{myBean.startIt}">
    <f:param name="request" value="AnyValue"/>
</h:commandLink>

Backing Bean Code:

String request= (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("request");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜