I am trying to select / deselect all the checkboxes in a datatable using a single checkbox. Since I am trying to install it on a server, I cannot do this. I was looking for solutions, but could not figure out how to do this 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
public void selectAllComponents(ValueChangeEvent event){
if(!selectAll)
{
changeMap(selectedComponentIds,true);
setSelectAll(true);
}
else
{
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 mark all the values in the list both truewhen the checkbox is checked and when the checkbox is unchecked false.
But the page does not reload the data correctly.
Is my method right for the problem? Or is there an effective alternative?
Abdul source
share