I have this selectOneMenu that asks for something, the default value is empty, because people need to think about the question and actually needs to fill it in.
<h:selectOneMenu id="fileSecurity" value="#{flowScope.application.fileSecurity}" required="true" >
<f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
<f:selectItem itemLabel="ja" itemValue="true" />
<f:selectItem itemLabel="nee" itemValue="false" />
</h:selectOneMenu>
This is what i have, now when you fill in the empty value it gives: “managementTabs:ApplicationManagementForm:fileSecurity : Needs to be filled in.”
wich is correct.
When i click yes or the true value it accepts the anwser.
But when i click no or false it gives:
“managementTabs:ApplicationManagementForm:fileSecurity: Validation Error: Value is not valid”
- Why does Jsf2.0 only accept true as the valid awnser and not false?
- Is there a way around this? Or do i have to write a custom validator?
It seems that a submitted value of
falseis conflicting with the empty string value ofnoSelectionOptionin some way. The following entries for the 1st item works fine:and
and
I only don’t understand why. It’s illogical. To find the real answer, I would need to run the debugger.
Update: I debugged and found the culprit in the
SelectUtils#valueIsNoSelectionOption()(Mojarra). The empty string of thenoSelectionOptionget coerced toboolean falseinstead ofBoolean nulland hence the comparison with the submitted value is valid and hence the selected value is invalid. This is “by design”. You really need to explicitly specify anitemValue="#{null}".