我试图使用一个复选框选择/取消选中数据表中的所有复选框.当我试图在服务器上设置它时,我无法这样做.我一直在寻找解决方案,但无法在服务器端获得如何完成.
这是代码.
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>
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在标记列表中的所有值,如true
选中复选框和false
未选中时.
但该页面无法正确重新加载数据.
我的方法是否正确处理问题?还是有一种有效的替代方案?
这是因为它ValueChangeEvent
发生在更新模型阶段之前,因此您更改的值会被覆盖.
这样做public void selectAllComponents(ValueChangeEvent event)
if (event.getPhase() != PhaseId.INVOKE_APPLICATION) {
event.setPhase(PhaseId.INVOKE_APPLICATON);
event.queue();
} else {
//do your stuff here
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14011 次 |
最近记录: |