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