3 Replies Latest reply on Dec 8, 2009 8:56 AM by Stefan Witte

    How to maintain the checked value of a disabled checkbox

    Stefan Witte Newbie

      We have a collection of checkboxes. Some of the checkboxes represent a mandatory option (configured in a table) and must be selected and the user should not be able to uncheck the checkbox.

      Right now we implemented this by creating a SelectItem collection and setting the mandatory selectItems disabled ("selectItem.setDisabled = true") in code. We also create a selected values list.

      selectableCategories = new SelectItem[categories.size()];
      selectedCategories = new ArrayList<String>();
      for (int i = 0; i < categories.size(); i++) {
       Category category = categories.get(i);
       selectableCategories[ i ] = new SelectItem();
       selectableCategories[ i ].setLabel(category.getDescription());
       selectableCategories[ i ].setValue(category.getId());
       selectableCategories[ i ].setDisabled(category.isMandatory());
       if (category.isSelected()) {

      and the managingbean has the following methods:

      public SelectItem[] getCategories() {
       return selectableCategories;
      public List<String> getSelect() {
       return selectedCategories;
      public void setSelect(List<String> selectedCategoryIds) {

      and the page code is:

      <form ....
      <h:selectManyCheckbox disabledClass="selectManyCheckbox_Disabled" styleClass="selectManyCheckbox" id="checkbox1" layout="pageDirection" value="#{projectBean.select}">
       <f:selectItems value="#{projectBean.categories}" />
      ... /form

      The form contains other text input fields. Now when i submit the form and there are validation errors the checked state of the disabled checkbox is not restored. My backingbean is not called because the validation phase prevents that so i am not able to restore the checked state on the mandatory/disabled checkbox.

      It looks like the disabled checkbox state, which should be 'checked', is ignored by the save/restore of the form.

      Does anyone know how to restore the checked state on the disabled checkbox when a validation error occurs ?

      (Using richfaces 3.3.2.SR1)