微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用JavaScript设置f:param值

有可能做到:

jsf代码(伪):

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

我的意思是接近,当< f:param>用JS设置.

这是不好的做法吗?

感谢帮助.

解决方法

您需要使用a4j的commandButton和actionParam才能将动态参数传递回服务器.

此外,您需要bean上的一个属性来接收param值.

例:

<a4j:commandButton action="#{myBean.action}" value="Submit!">
    <a4j:actionParam name="arg" noEscape="true" value="getTheValue()" assignTo="#{myBean.myBeanArg}" />
</a4j:commandButton>

这里myBean.myBeanArg将接收javascript函数getTheValue()返回的值.

注意noEscape =“true”属性.这是必需的,因为否则内部值的数据将用单引号括起来并进行转义,从而导致无法执行javascript.如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>.

原文地址:https://www.jb51.cc/js/150173.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐