Following example:
<h:selectOneMenu value="#{bean.value}">
<f:selectItem itemValue="#{null}" itemDisabled="#{true}" noSelectOption="#{true}" itemLabel="choose one" />
<f:selectItem itemValue="FEMALE" itemLabel="female" />
<f:selectItem itemValue="MALE" itemLabel="male" />
<f:converter converterId="myConverter" />
</h:selectOneMenu>
On initial load the value of the bean is null
so the please-choose-option is selected. If the user chooses nothing the browser won’t submit a value (the selected option is disabled) and JSF will set the value to an empty String. If the page is rendered again there is no according value, JSF won't render a selected-attribute and most browsers will preselect the first non-disabled-value. Bad.
I thought I could easily change this with a Converter which converts the empty String to null
in getAsObject
. But in this case the converter is not called.
Anybody knows why?
I know that I could change this behaviour with javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
but this leads to other problems with other fields.
null
option? – Mr.J4mes