开发者

Set f:param value with JavaScript

Is it possible to do:

jsf code (pseudo):

...
<f:param name="arg" value="document.getElementById('namin开发者_如何学Cg').text()">
<h:inputText id="naming"></h:inputText>
...

I mean approach,when <f:param> is set with JS.

Is it bad practice?

Thanks for help.


You need to use a4j's commandButton and actionParam to be able to pass a dynamic param back to the server.

Additionally, you need an attribute on your bean that will receive the param value.

Example:

<a4j:commandButton action="#{myBean.action}" value="Submit!">
    <a4j:actionParam name="arg" noEscape="true" value="getTheValue()" assignTo="#{myBean.myBeanArg}" />
</a4j:commandButton>

Here myBean.myBeanArg will receive the value returned by the javascript function getTheValue().

Notice the noEscape="true" attribute. This is needed because otherwise the data inside value would be enclosed in single quotes and escaped, resulting in no javascript execution. As stated in the documentation:

It is possible to use JavaScript expression or function in the "value" attribute. In this case the "noEscape" attribute should be set to "true". The result of this JavaScript invocation is sent to the server as a value of <a4j:actionparam>.


<f:param> is server side stuff while javascript is client side. So you can't

You can use ajax a4j to do this ,


No you can't. You could change an attribute of a link for example and get this attribute in your action method ont he server side.

Alternatively you could use an hidden input field linked to an attribute in your bean.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜