开发者

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

开发者 https://www.devze.com 2023-03-24 23:44 出处:网络
This question already has answers here:开发者_如何学C Validation Error: Value is not valid (3 answers)
This question already has answers here: 开发者_如何学C Validation Error: Value is not valid (3 answers) Closed 7 years ago.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消