how to create selectAll checkbox in JSF-2

核能气质少年 提交于 2019-12-25 02:09:03

问题


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

Thanks, alex


回答1:


Depends on what you are trying to achieve.

For example, you can load your checkboxes within <f:form> with

<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>

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);
    }
 }

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.

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.



来源:https://stackoverflow.com/questions/14806136/how-to-create-selectall-checkbox-in-jsf-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!