1

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.

wrschneider
  • 17,913
  • 16
  • 96
  • 176
  • First this, do you have `INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL` context param set to `true` in your `web.xml`? – BalusC Dec 02 '11 at 03:31
  • @BalusC - no, I didn't have that context param set. Adding it actually had the opposite effect: `h:inputText` with `required="true"` would not display the blank value from the form submission, and instead would revert to the value in the bean. – wrschneider Dec 02 '11 at 14:43
  • could it be a defect? http://java.net/jira/browse/JAVASERVERFACES-932 – wrschneider Dec 05 '11 at 20:49
  • Just updated JAVASERVERFACES-932 with comment showing impacted part of `MenuRenderer.java` – wrschneider Jan 20 '12 at 16:52
  • I'm not able to login in java.net/jira/browse/JAVASERVERFACES-932. There is any correction path to this behavior? – MaikoID Apr 12 '13 at 13:12

0 Answers0