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.
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 ,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With