Description
I discovered that MyFaces doesn't seem to handle null values correctly in listboxes and menus.
See the following example showing a h:selectOneMenu used to select an enum value:
@ManagedBean
@RequestScoped
public class TestBean {
public enum Level
{ HIGH, MEDIUM, LOW }private Level level;
public String action()
{ FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Submitted level: " + level)); return null; }}
And the following view:
<h:selectOneMenu value="#
{testBean.level}" label="Level">
<f:selectItem itemValue="#
" itemLabel="Unknown"/>
<f:selectItem itemValue="HIGH" itemLabel="High"/>
<f:selectItem itemValue="MEDIUM" itemLabel="Medium"/>
<f:selectItem itemValue="LOW" itemLabel="Level"/>
</h:selectOneMenu>
<h:commandButton action="#
{testBean.action}" value="Go"/>
Clicking the "Go" button will result in the validation error: "Level: 'Unknown' must be convertible to an enum."
If the value of the select item is null, MyFaces won't render the value attribute of the option and so the browser will submit the label as its value:
<select id="levelForm:level" name="levelForm:level" size="1">
<option selected="selected">Unknown</option>
<option value="HIGH">High</option>
<option value="MEDIUM">Medium</option>
<option value="LOW">Level</option>
</select>
Mojarra instead renders an empty value attribute in this situation:
<option value="" selected="selected">Unknown</option>
I've created a patch fixing this issue against the current trunk of myfaces-shared and attached it to this ticket.
You can see the sample application reproducing this issue here:
http://github.com/chkal/myfaces-tests/tree/menu-null-value
And download it here:
http://github.com/chkal/myfaces-tests/archives/menu-null-value
Attachments
Attachments
Issue Links
- is related to
-
MYFACES-2739 Pass through String values in EnumConverter.getAsString()
- Closed