6

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.

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

Comments

4

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

You can use ajax a4j to do this ,

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.