Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JSF中选中所有复选框,而不使用Javascript_Jsf_Richfaces - Fatal编程技术网

在JSF中选中所有复选框,而不使用Javascript

在JSF中选中所有复选框,而不使用Javascript,jsf,richfaces,Jsf,Richfaces,我正在尝试使用单个复选框选择/取消选择datatable中的所有复选框。因为我试图在服务器上设置它,所以我无法这样做。我四处寻找解决方案,但无法在服务器端实现 这是代码 xhtml文件### Java文件 // Select All and delete public void selectAllComponents(ValueChangeEvent event){ // If the check all button is checked, set all the checkbox

我正在尝试使用单个复选框选择/取消选择datatable中的所有复选框。因为我试图在服务器上设置它,所以我无法这样做。我四处寻找解决方案,但无法在服务器端实现

这是代码

xhtml文件###


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);
  }
 }
//选择全部并删除
public void selectAllComponents(ValueChangeEvent事件){
//如果选中“全选”按钮,则将所有复选框设置为选中状态
如果(!selectAll)
{
changeMap(SelectedComponentDS,true);
setSelectAll(真);
}
否则//如果未选中该按钮,请取消选中所有复选框
{ 
changeMap(SelectedComponentDS,false);
setSelectAll(假);
}
}
public void changeMap(映射选择的组件映射,布尔bln值){
如果(selectedComponentMap!=null){
迭代器itr=selectedComponentMap.keySet().Iterator();
while(itr.hasNext()){
selectedComponentMap.put(itr.next(),blnValue);
}
设置SelectedComponentDS(selectedComponentMap);
}
}
选中复选框时,我将列表中的所有值标记为
true
,未选中复选框时,我将列表中的所有值标记为
false

但是页面没有正确地重新加载数据


我处理这个问题的方法正确吗?还是有一个有效的替代方案?

这是因为
ValueChangeEvent
发生在更新模型阶段之前,因此您更改的值会被覆盖。
public void选择所有组件(ValueChangeEvent事件)


或者在代码之前,在原始方法中添加下一行代码


selectAll=(布尔)event.getNewValue()

正确的方法名是getPhaseId()和setPhaseId(),如规范中所述。请看,如果不包含Adam答案中给出的代码,它对我来说不起作用:
// 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);
  }
 }
if (event.getPhase() != PhaseId.INVOKE_APPLICATION) {
    event.setPhase(PhaseId.INVOKE_APPLICATON);
    event.queue();
 } else {
    //do your stuff here
 }