I am trying to figure out following problem. I have a simple rich:select
<rich:select listWidth="310" id="userSelect" value="#{departmentBacking.selectedUserId}"
disabled="#{departmentBacking.unassignCheckbox}"enableManualInput="true" defaultLabel="#{not departmentBacking.unassignCheckbox ? 'start typing a surname...' : 'Uncheck unassign departments first'}">
<f:selectItems value="#{departmentBacking.userList}" var="user" itemValue="#{user.id}" itemLabel="#{user.surname} #{user.name} - #{user.email}" />
</rich:select>
It selects a person who is later set as leader of some departments. Works well. However, if I only need to unassign departments, without choosing new one, problems start to occur. If the unnassignCHeckbox is selected, I don’t want to use this value at all. However, I cannot make the jsf engine to do the postback, since I always get a validation error.
MyForm:userSelect: Validation Error: Value is not valid
I assume this is because the default value of #{user.id} is 0 and no user with this id is to be found in userList. The bean is view scoped. Is there a way to somehow either skip the validation or exclude the rich:select from the submitting form?.
Try adding a
<f:selectItem>with the 0 value and a “SELECT” label (or whatever). That will solve your problem, and add a validation that when the unnassignCHeckbox is unselected, the selectedUserId value must be greater than 0 (this last only if its not yet implemented).