I have something like this on a create/edit form:
<h:selectOneMenu value="#{bean.value}" required="true" ... >
<f:selectItem itemLabel="-- Select --" itemValue=""/>
<f:selectItems .../>
</h:selectOneMenu>
In the create new object case, the required
validation works as expected.
In the edit object case, if I change a valid value to the placeholder "-- Select --", I get the validation failure w/expected requiredMessage because itemValue is blank (""); however, the HTML <select>
reverts to whatever option was already selected from the bean, rather than retaining the invalid user input from form submission.
To reiterate, the required=true
on the h:selectOneMenu
itself works fine, generating the expected message - the only thing that's wrong is the value reverting to the bean value, instead of retaining the blank submitted value. (I confirmed with Chrome developer toolbar that an empty string is indeed being POSTed for the <select>
.)
Why is this happening? More precisely, why is h:selectOneMenu
not behaving like h:inputText
, where the UIInput displays the invalid user input from the form, and does not refresh its value from the bean? Both of these controls extend the same UIInput base class and implement EditableValueHolder, so I expect their lifecycle would behave the same.
Also, to clarify, I do not have the INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
context param anywhere in web.xml.
This is a JSF application on Mojarra 2.1.3 / Glassfish 3.1.1.