MyFaces Core
  1. MyFaces Core
  2. MYFACES-2927

Invalid handling of null values in listboxes and menus


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.0.3
    • Component/s: General
    • Labels:


      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:

      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="#


      " 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:commandButton 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>

      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:

      And download it here:

      1. MYFACES-2927.patch
        0.8 kB
        Christian Kaltepoth

        Issue Links


          Christian Kaltepoth created issue -
          Christian Kaltepoth made changes -
          Field Original Value New Value
          Status Open [ 1 ] Patch Available [ 10002 ]
          Christian Kaltepoth made changes -
          Attachment MYFACES-2927.patch [ 12455120 ]
          Leonardo Uribe made changes -
          Link This issue is related to MYFACES-2739 [ MYFACES-2739 ]
          Leonardo Uribe made changes -
          Status Patch Available [ 10002 ] Resolved [ 5 ]
          Assignee Leonardo Uribe [ lu4242 ]
          Fix Version/s 2.0.3-SNAPSHOT [ 12315349 ]
          Resolution Fixed [ 1 ]
          Leonardo Uribe made changes -
          Fix Version/s 2.0.3 [ 12315976 ]
          Fix Version/s 2.0.3-SNAPSHOT [ 12315349 ]
          Leonardo Uribe made changes -
          Status Resolved [ 5 ] Closed [ 6 ]


            • Assignee:
              Leonardo Uribe
              Christian Kaltepoth
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: