使用javascript基于JSF复选框启用/禁用JSF命令按钮 [英] JSF command button enable/disable based on JSF check box using javascript

查看:64
本文介绍了使用javascript基于JSF复选框启用/禁用JSF命令按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RichFaces,我希望启用/禁用 h:commandButton 基于 h:selectBooleanCheckbox 使用Javascript。默认情况下,应禁用该按钮并取消选中复选框。选中该复选框时应启用该按钮,并在取消选中该复选框时禁用该按钮。

I am using RichFaces and I want to enable/disable h:commandButton based on h:selectBooleanCheckbox using Javascript. By default the button should be disabled and check box unchecked. The button should be enabled when the check box is selected and disabled when the check box is deselected.

非常感谢任何帮助。

推荐答案

如上所述来自Openfaces的Dmitry,启用/禁用面部组件(Primefaces,Openfaces,Richfaces等)必须在服务器端完成。
今后更好的解决方案是在触发更改事件时使用ajax! onchange事件适用于这种情况(例如,假设使用键盘选中/取消选中复选框)!

As stated by Dmitry from Openfaces, Enabling/Disabling a faces components (Primefaces, Openfaces, Richfaces...etc) must be done on server side. A better solution is henceforth to use ajax when a change event is fired! onchange event is suitable for this situation (imagine the checkbox is checked/unchecked using Keyboard for example)!

<h:selecBooleanCheckbox id="box" value="#{mybean.selecteditem.booleanvalue}"......>
<f:ajax execute="box" render="but" event="change" />
</h:selectBooleanCheckbox>

<h:commandButton id="but" action="someAction" value="someValue" disabled="#{!mybean.selecteditem.booleanvalue}" />

这样,当取消选中该复选框时,命令Button被禁用,但是当选中时,按钮是启用。

This way, when the checkbox is unchecked, the command Button is disabled, but when checked the button is enabled.

如果 Primefaces 使用< p:ajax /> 建议使用!

<p:ajax event="change" process="box" update="but"/>

如果是 OpenFaces ,则< f:ajax /> < o:ajax /> 工作正常。

In case of OpenFaces, both <f:ajax /> and <o:ajax /> work fine.

如果你有多个组件要同时渲染,juste包含它们的id,空格分隔:

And if you have multiple components to render at the same time, juste include their ids, space separated :

<f:ajax ......render="id1 id2 id3" />

这篇关于使用javascript基于JSF复选框启用/禁用JSF命令按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆