marque a caixa de seleção Todos no JSF sem usar Javascript
Estou tentando marcar / desmarcar todas as caixas de seleção na tabela de dados usando uma única caixa de seleção. Como estou tentando configurá-lo no servidor, não consigo fazer isso. Eu procurei por soluções, mas não consegui entender como realizar isso no lado do servidor.
Aqui está o código.
arquivo xhtml ###
<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>
Arquivo Java
// 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);
}
}
Estou marcando todos os valores na lista comotrue
quando a caixa de seleção estiver marcada efalse
quando desmarcada.
Mas a página não recarrega os dados corretamente.
Meu método de abordagem do problema está correto? Ou existe uma alternativa eficiente?