10

I have a JSF:Primefaces SelectCheckBoxMenu

<p:selectCheckboxMenu value="#{domain.listaa}" label="Chooese!" style="height:25px" showCheckbox="true">
    <p:ajax update="records" listener="#{domain.muti}" />  
    <f:selectItems value="#{domain.recLabels}"/>
</p:selectCheckboxMenu>

In the managed beans:

private boolean[] recFlags = new boolean[]{true,true,true,true,true,true,true};
private String[] recLabels = new String[]{"A","AAAA","MX","NS","SOA","CNAME","TXT"};
private List<String> listaa = new ArrayList<>();

public void muti(AjaxBehaviorEvent event){
    Arrays.fill(recFlags, false);
    for(int i=0;i<recLabels.length;i++){
        if(listaa.contains(recLabels[i])){
            recFlags[i]=true;
        }
    }
    System.out.println(listaa.toString());
}

So in the SelectCheckBoxMenu I press any button, the ajax call is working, and the muti() function will run. There is no problem. But if I press the 'select all' (most above) button in the SelectCheckboxMenu, the ajax call is not working, muti() function won't run and the listaa (List about the pressed checkboxs) is not changing. Why? How can I solve, that 'select all' button works?

3 Answers 3

22

In Primefaces 4 and 5 there is a special ajax event for 'Toggle all' checkbox - toggleSelect.

Just add it with the same attributes as your default ajax event.

<p:selectCheckboxMenu value="#{domain.listaa}" label="Chooese!" style="height:25px" showCheckbox="true">
    <p:ajax update="records" listener="#{domain.muti}" />  
    <p:ajax event="toggleSelect" update="records" listener="#{domain.muti}" />
    <f:selectItems value="#{domain.recLabels}"/>
</p:selectCheckboxMenu>
2
  • I have this problem in Primefaces 6 and I cannot update to newer version, when unselecting all the listener is not being invoked. Any alternative to deal with this? Commented Aug 17, 2022 at 14:00
  • Thank you so much. The toggleSelect is what was missing in my code.
    – fayabobo
    Commented Apr 26, 2023 at 12:55
1

This works.

<p:ajax event="toggleSelect"  process="@this" partialSubmit="true" />
2
  • 1
    Welcome to Stack Overflow! Could you add some details of why this should work? Code-only answers are not very useful and are subject to deletion.
    – Cristik
    Commented Nov 27, 2015 at 14:29
  • Indeed, it worked. But only for select all option. For remaining options, another event 'change' has to be added. Commented Jul 13, 2016 at 5:00
0

Yes, this is a reported issue as far as I know: http://code.google.com/p/primefaces/issues/detail?id=4788&q=SelectCheckboxMenu&colspec=ID%20Type%20Status%20Priority%20TargetVersion%20Reporter%20Owner%20Summary

Open since 2012. Not fixed yet.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.