I am trying to select/unselect all checkboxes in the datatable using a single checkbox. As I am trying to set it on the server, I am unable to do so. I have looked around for solutions but could not get how to accomplish on the server side.
Here is the code.
xhtml file###
<rich:column styleClass="center-aligned-text">
<f:facet name="header">
<h:selectBooleanCheckbox id="selectAll" title="selectAll" valueChangeListener="#{workspace.selectAllComponents}">
<a4j:support event="onclick" reRender="listcomponents"/>
</h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox id="selectComponent"
value="#{workspace.selectedComponentIds[componentInfo.id]}">
</h:selectBooleanCheckbox>
</rich:column>
Java File
// Select All and delete
public void selectAllComponents(ValueChangeEvent event){
// If the check all button is checked, set all the checkboxes as selected
if(!selectAll)
{
changeMap(selectedComponentIds,true);
setSelectAll(true);
}
else // If the button is unchecked, unselect all the checkboxes
{
changeMap(selectedComponentIds,false);
setSelectAll(false);
}
}
public void changeMap(Map<Long,Boolean> selectedComponentMap, Boolean blnValue){
if(selectedComponentMap != null){
Iterator<Long> itr = selectedComponentMap.keySet().iterator();
while(itr.hasNext()){
selectedComponentMap.put(itr.next(), blnValue);
}
setSelectedComponentIds(selectedComponentMap);
}
}
I am marking all the values in the list as true
when the checkbox is checked and false
when unchecked.
But the page doesn't reload the data properly.
Is my method to approach to the problem correct? Or is there a efficient alternative?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…