1

I found some weird behaviour with p:selectManyCheckbox. On page load, two checkbox values are selected and one of the checkbox is disabled conditionally. If i deselect the one of checkbox(not disabled), it deselect the disabled one as well.

if i try to debug the code, the setter is updated with empty array.

This wll happen only for the disabled check box. I am using the Primefaces 5.2 and JSF 2.2 version.

Xhtml

<h:form id="mulitpleCheckboxTest">
 <p:selectManyCheckbox id="multicheckBoxTest" 
    value="#{indexManagedBean.selectedCheckBox}" layout="grid" columns="1">
    <f:selectItems value="#{indexManagedBean.checkBoxValues}" 
    var="number" itemValue="#{number}" itemDisabled="#{'four' eq number}" />
    <p:ajax update="@form"></p:ajax>
</p:selectManyCheckbox>

Managed Bean:

@ManagedBean
@ViewScoped
public class IndexManagedBean {

    private List<String> checkBoxValues;

    private List<String> selectedCheckBox;

    @PostConstruct
    public void init() {
        selectedCheckBox = new ArrayList<String>();
        checkBoxValues = new ArrayList<String>();
        popoulateCheckBoxValues();
        selectedCheckBox.add("four");
        selectedCheckBox.add("Two");

    }

    public List<String> getCheckBoxValues() {
        return checkBoxValues;
    }

    public void setCheckBoxValues(List<String> checkBoxValues) {
        this.checkBoxValues = checkBoxValues;
    }

    public List<String> getSelectedCheckBox() {
        return selectedCheckBox;
    }

    public void setSelectedCheckBox(List<String> selectedCheckBox) {
        this.selectedCheckBox = selectedCheckBox;
    }

    private void popoulateCheckBoxValues() {
        checkBoxValues.add("One");
        checkBoxValues.add("Two");
        checkBoxValues.add("Three");
        checkBoxValues.add("four");
        checkBoxValues.add("five");
        checkBoxValues.add("six");
        checkBoxValues.add("seven");
        checkBoxValues.add("eight");
        checkBoxValues.add("nine");
        checkBoxValues.add("ten");
   }
}
Newbie
  • 41
  • 6
  • Any chance you can move to a newer version of Primefaces? I encountered many problems, specifically with the SelectManyCheckbox (see here: https://stackoverflow.com/questions/47054616/primefaces-selectcheckboxmenu-erratic-behavior-when-deselecting-individual-check/47135949#47135949). All Problems where solved by upgrading to Primefaces 6.1.8. – Robert Apr 11 '18 at 09:17
  • Thanks Robert for the Info. Right now, we don't have any plans to upgrade to newer version. I found a workaround for this, based on the my business use case(a kind of hack). Let me try with 6.1.8 version. – Newbie Apr 16 '18 at 08:00

0 Answers0