使用JavaScript设置f:param值 [英] Set f:param value with JavaScript
问题描述
是否可以这样做:
jsf code(伪):
jsf code (pseudo):
...
<f:param name="arg" value="document.getElementById('naming').text()">
<h:inputText id="naming"></h:inputText>
...
我的意思是接近,当< f :param>
是用JS设置的。
I mean approach,when <f:param>
is set with JS.
这是不好的做法吗?
感谢您的帮助。
推荐答案
您需要使用a4j的 commandButton
和 actionParam
能够将动态参数传递回服务器。
You need to use a4j's commandButton
and actionParam
to be able to pass a dynamic param back to the server.
此外,你需要一个接收param值的bean的属性。
Additionally, you need an attribute on your bean that will receive the param value.
示例:
<a4j:commandButton action="#{myBean.action}" value="Submit!">
<a4j:actionParam name="arg" noEscape="true" value="getTheValue()" assignTo="#{myBean.myBeanArg}" />
</a4j:commandButton>
这里 myBean.myBeanArg
将收到该值由javascript函数返回 getTheValue()
。
Here myBean.myBeanArg
will receive the value returned by the javascript function getTheValue()
.
注意 noEscape =true
属性。这是必需的,因为否则值
中的数据将被包含在单引号中并进行转义,从而导致无法执行javascript。如文档<中所述/ a>:
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:
可以在value
属性中使用JavaScript表达式或函数。在这种情况下,noEscape属性应设置为
true。此JavaScript调用的结果将作为< a4j:actionparam>
的值发送到服务器
。
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>
.
这篇关于使用JavaScript设置f:param值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!