Checkbox JSF-2使用单个复选框选择/取消选择所有复选框列表

Checkbox JSF-2使用单个复选框选择/取消选择所有复选框列表,checkbox,richfaces,jsf-2.2,Checkbox,Richfaces,Jsf 2.2,我在rich:dataTable中有一个复选框列表,我想用header列中的一个复选框一次选中所有复选框 <rich:column id="includeInWHMapping" > <f:facet name="header"> <h:selectBooleanCheckbox value="#{checkallbox.selectAll}"> <f:ajax actionListener="#{che

我在rich:dataTable中有一个复选框列表,我想用header列中的一个复选框一次选中所有复选框

<rich:column id="includeInWHMapping" >
      <f:facet name="header">
        <h:selectBooleanCheckbox value="#{checkallbox.selectAll}">
           <f:ajax actionListener="#{checkallbox.selectAllBox}" render="selectedForWHProcess" />
        </h:selectBooleanCheckbox>  
      </f:facet>        
      <h:selectBooleanCheckbox id="selectedForWHProcess" value="#{checkallbox.checked[data]}">      
         <f:ajax actionListener="#{checkallbox.selectAllRows}"/>
      </h:selectBooleanCheckbox></rich:column>

checkallbox Bean中的代码:

private Map<StandardStructure, Boolean> checked = new HashMap<StandardStructure, Boolean>();        
private boolean selectAll;

public boolean isSelectAll() {
    return selectAll;
}

public void setSelectAll(boolean selectAll) {
    this.selectAll = selectAll;
}

public Map<StandardStructure, Boolean> getChecked() {
    return checked;
}

public void setChecked(Map<StandardStructure, Boolean> checked) {
    this.checked = checked;
}

public void selectAllBox(ValueChangeEvent e){
    boolean newSelectAll = (Boolean) e.getNewValue();
    Iterator<StandardStructure> keys = checked.keySet().iterator();
    while(keys.hasNext()){
        StandardStructure ss = keys.next();
        checked.put(ss, newSelectAll);
    }
}
private Map checked=new HashMap();
私有布尔selectAll;
公共布尔值isSelectAll(){
返回selectAll;
}
公共void setSelectAll(布尔selectAll){
this.selectAll=selectAll;
}
公共地图getChecked(){
退货检查;
}
公共无效设置已选中(映射已选中){
this.checked=checked;
}
public void selectAllBox(值更改事件e){
布尔newSelectAll=(布尔)e.getNewValue();
迭代器键=选中的.keySet().Iterator();
while(keys.hasNext()){
标准结构ss=keys.next();
选中。放置(ss,newSelectAll);
}
}
当我选中标题列的h:SelectBoolean复选框时,什么都没有发生。我错过了什么?我是否也必须为“selectAll”属性实现映射


谢谢。首先
f:ajax
没有
actionListener
,它有一个
监听器。阅读文档。第二件事,您可以在
h:selectBooleanCheckbox
上使用
valueChangeListener
,并且只在那里使用。第三,行框中的侦听器是错误的。基本上,看起来你需要阅读

下面是一个工作示例:

<h:form>
    <rich:dataTable value="#{checkallbox.allValues}" var="data" id="dataTable">
        <rich:column>
            <f:facet name="header">
                <h:selectBooleanCheckbox value="#{checkallbox.selectAll}"
                    valueChangeListener="#{checkallbox.selectAllBox}">
                    <f:ajax render="dataTable" />
                </h:selectBooleanCheckbox>
            </f:facet>
            <h:selectBooleanCheckbox value="#{checkallbox.checked[data]}">
                <f:ajax />
            </h:selectBooleanCheckbox>
        </rich:column>

        <!-- other columns -->
    </rich:dataTable>
</h:form>

    谢谢你,埃米尔!我解决了

    public void selectAllBox(){
        if(!selectAll){
            for(StandardStructure item : ssTable.getDto()){
                checked.put(item, true);
            }
        }else{
            for(StandardStructure item : ssTable.getDto()){
                checked.put(item, false);
            }
        }
    }
    

    selectAllBox
    是否已激发,您是否尝试渲染整个表?@EmilSierżęga是的,已激发,但在复选框列表中未看到此类更改。我没有渲染整个表,而是渲染复选框列。谢谢你的回复!你必须渲染整张桌子。不能只渲染“列”。在呈现的HTML中,没有列这样的东西,所以您不希望呈现多个id为的
    ,比如
    tableId:\u NUMBER\u:selectedForWHProcess
    。阅读这两个主题:和@EmilSierżęga嘿,谢谢!但是我该怎么做呢?我是JSF新手。对不起!:)为什么不试着渲染整张桌子呢?谢谢Emil!我真的很感谢你的努力。我没有使用@PostConstruct。但现在它起作用了。现在我唯一的问题是分页时,所有复选框都未选中,但行都已选中。很高兴我能提供帮助,但问题似乎已解决,因为您已将答案标记为已接受:-)实际上我已接受您的答案!我想念我的P再次接受了你的回答!谢谢!:)这不是你问题的答案,而是你想要的。
    public void selectAllBox(){
        if(!selectAll){
            for(StandardStructure item : ssTable.getDto()){
                checked.put(item, true);
            }
        }else{
            for(StandardStructure item : ssTable.getDto()){
                checked.put(item, false);
            }
        }
    }