Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation Error: Value is not valid for SelectManyCheckBox [duplicate]

Tags:

jsf

jsf-2

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?

like image 428
Raj Avatar asked May 14 '26 06:05

Raj


1 Answers

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.

like image 83
BalusC Avatar answered May 19 '26 04:05

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!