简体   繁体   中英

Checking 'check all' checkbox doesn't call p:ajax tag JSF

ajax doesn't work when I check 'check all box' checkbox.

 <p:selectCheckboxMenu id="departmantCheckBox" value="#{marketAnalysisReportController.selectedDepartmants}"  filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
            <p:ajax update="saleCheckBox" listener="#{marketAnalysisReportController.updateSales}"/>
            <f:selectItems value="#{marketAnalysisReportController.departmants}" var="departmant"
                            itemValue="#{departmant}"
                            itemLabel="#{departmant.name}"/>
        </p:selectCheckboxMenu>

Here's update method

public void updateSales(){
        sales=new ArrayList<Obje>();
        System.out.println("updatesales");
        for(Obje departmant: selectedDepartmants){
            System.out.println(departmant.name);
            if(departmant.getName().equals("test1")){
                sales.add(new Obje(20,"salestest20"));
                sales.add(new Obje(21,"salestest21"));
                System.out.println("add");
            }
            if(departmant.getName().equals("test2")){
                sales.add(new Obje(200,"salestest200"));
                sales.add(new Obje(210,"salestest210"));
            }
            if(departmant.getName().equals("test3")){
                sales.add(new Obje(250,"salestest250"));
                sales.add(new Obje(260,"salestest260"));
            }
            if(departmant==null || departmant.equals("")){
                sales=new ArrayList<Obje>();
            }
        }
    }

If I check boxes one by one, it works, but when I check 'check all checkboxes' it doesn't update sales. I can share more detail if you need.

As Kukeltje allready pointed out the 'select all'- action does not fire the default ajax event which is caught by your tag. The ajax event that is being fired when you select all is called 'toggleSelect', so you need to add another ajax tag like this:

< p:ajax event="toggleSelect"...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM