3

I am new to JSF, I am getting the following error for <h:selectManyCheckBox>:

Validation Error: Value is not valid

This is my model:

private List<String> selectedRoles;
public List<SelectItem> availableRolesSelectItem;

for (Role role : rolesList) {
    SelectItem option = new SelectItem(role.getName(), role.getName() + " " + role.getDescription());
    availableRolesSelectItem.add(option);
}

This is my view:

<h:selectManyCheckbox value="#{mybean.selectedRoles}" required="true" requiredMessage="#{errormessages.valueRequired}">
    <f:selectItems value="#{mybean.availableRolesSelectItem}" />
</h:selectManyCheckbox>

In the SelectItem I am not assigning Role object as item value, I am just assigning a String value. Even though I am getting the error.

Can you guys help me on this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Raj
  • 31
  • 1
  • 2

1 Answers1

4

You get this error whenever the selected value(s) doesn't match any of the available values during the request of processing the form submit. You need to ensure that the availableRolesSelectItem is exactly the same during the request of processing the form submit as it was during displaying the form. Ideally, you would do the availableRolesSelectItem filling job in the bean's (post)constructor.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555