如何在JSF-2中创建selectAll复选框 [英] how to create selectAll checkbox in JSF-2

查看:203
本文介绍了如何在JSF-2中创建selectAll复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JSF -2中创建全选复选框以选择页面中的所有选择框,而不是在其他页面上,因为这些复选框是列表,并在每个页面中显示20个...

how can I create select All checkbox in JSF -2 to select all select boxes in the page only not on the other page as these check boxes are the list and displaying 20 in each page...

感谢,
alex

Thanks, alex

推荐答案

取决于你想达到的目标。

Depends on what you are trying to achieve.

例如,您可以在< f:form> 中加载

<h:commandButton actionListener="{#myBean.checkAll}">
    <f:ajax render="checkboxes">
</h:commandButton>
<h:panelGroup id="checkboxes">
    <ui:repeat var="check" value="#{myBean.checkBoxes}">
    <h:selectBooleanCheckbox value=#{check.checked}/>
    <h:outputText value=#{check.checkedCaption}/>
    </ui:repeat>
</h:panelGroup>

然后,您可以使用以下bean方法和部分页面更新来检查所有这些:

Then you can check them all with the following bean method and partial page update:

public void checkAll(ActionEvent event){
    for(Check check : checkBoxes) {
        checkBoxes.setChecked(true);
    }
 }

取消选中所有功能可以通过以下方式,当您使用与当前复选框状态相反的操作侦听器方法替换true时。

The uncheck all functionality can be achieved in the following manner, when you replace true in action listener method with the opposite of the current check box state.

编辑。如果要在稍后执行所选属性的服务器端设置,例如在保存按钮单击期间,您可能需要检查/取消选中客户端上的检查按钮。所以,如果你使用jQuery 1.6+,你可以调用 $('。checkbox')。prop('checked',true); presetting 在您的视图中,styleClass =checkbox of < h:selectBooleanCheckbox> 为了做到这一点,你可以,例如,绑定一个按钮的javascript onclick方法与上面提出的简单的JavaScript。

Edit. If you want to perform server-side setting of checked properties later, for example during save button click, you may want to check/uncheck the checkbuttons on the client. So, if you are using jQuery 1.6+, you may call $('.checkbox').prop('checked', true); presetting styleClass="checkbox" of <h:selectBooleanCheckbox> in your view. To do this, you may, for example, bind javascript onclick method of a button with the simple javascript proposed above.

这篇关于如何在JSF-2中创建selectAll复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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