Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set f:param value with JavaScript

Is it possible to do:

jsf code (pseudo):

...
<f:param name="arg" value="document.getElementById('naming').text()">
<h:inputText id="naming"></h:inputText>
...

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

Is it bad practice?

Thanks for help.

like image 358
sergionni Avatar asked Apr 07 '11 10:04

sergionni


2 Answers

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>.

like image 109
Yuri Ghensev Avatar answered Sep 27 '22 17:09

Yuri Ghensev


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

You can use ajax a4j to do this ,

like image 20
jmj Avatar answered Sep 27 '22 18:09

jmj