Set f: parameter value using 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 the approach when <f:param> installed using JS.

Is this a bad practice?

Thanks for the help.

+6
source share
3 answers

You need to use commandButton and actionParam to pass the dynamic parameter back to the server.

In addition, you need an attribute of your bean that will receive the parameter 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 get the value returned by the javascript getTheValue() function.

Note the noEscape="true" attribute. This is necessary because otherwise the data inside the value will be enclosed in single quotes and escaped, which will lead to javascript execution. As stated in the documentation :

You can use an expression or JavaScript function in the value of the "value" attribute. In this case, the noEscape attribute should be set to true. The result of this JavaScript call is sent to the server as the value of <a4j:actionparam> .

+6
source

<f:param> is part of the server side, and javascript is the client side. Therefore you cannot

You can use ajax a4j for this,

+4
source

No, you can’t. You can change the link attribute, for example, and get this attribute in your server-side action method.

Alternatively, you can use the hidden input field associated with the attribute in the bean.

0
source

Source: https://habr.com/ru/post/885401/


All Articles