Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-1759

JSR-252 Issue #69: Permit the passing of a null value to SelectItem.setValue(). A SelectItem with null value adds message Value is not valid

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.2.2
    • JSR-252
    • None
    • tomcat 6, myfaces-1.2.1-SNAPSHOT (05 nov 2007)

    Description

      The following code:

      <h:selectOneListbox id="si" binding="#

      {selectItemBean.component}

      "
      value="#

      {selectItemBean.value}

      ">
      <f:selectItems value="#

      {selectItemBean.list}

      "/>
      </h:selectOneListbox>

      If the list is created as is:

      public List<SelectItem> getList()

      { List<SelectItem> lista = new ArrayList<SelectItem>(); lista.add(new SelectItem(null, "NULL 2"); lista.add(new SelectItem("", "EMPTY")); lista.add(new SelectItem("1", "Value 1")); lista.add(new SelectItem("2", "Value 2")); return lista; }

      Render this:

      <select id="form:si" name="form:si" size="4">
      <option value="" selected="selected">NULL 2</option>
      <option value="" selected="selected">EMPTY</option>
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
      </select>

      null and empty String values are annotated equally.

      The problem is that JSF RI assumes value="" as null when converting the value, but myfaces assumes empty String.

      The submited value is an empty String, decoded on JSF RI as null and on Myfaces as empty String.
      JSF RI does not show this item as selected but set the value
      correctly to null. Myfaces sends a validation message "Validation Error: Value is not valid".

      To be according to the spec, the preferred behavior is that JSF RI shows, so it's necessary a correction on myfaces to be compatible.

      Attachments

        1. patchNullUISelectOne.patch
          5 kB
          Leonardo Uribe

        Activity

          People

            Unassigned Unassigned
            lu4242 Leonardo Uribe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: