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

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...