h:selectOneMenu required=“true” reverts to bean value on validation failure

十年热恋 提交于 2019-12-31 03:48:27

问题


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.

来源:https://stackoverflow.com/questions/8351326/hselectonemenu-required-true-reverts-to-bean-value-on-validation-failure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!