ICEfaces
  1. ICEfaces
  2. ICE-9385

ace:simpleSelectOneMenu - Support 'javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL' (was NullPointerException in ace:simpleSelectOneMenu)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.3
    • Fix Version/s: 4.0.BETA, EE-3.3.0.GA_P02, 4.0
    • Component/s: ACE-Components
    • Labels:
      None
    • Environment:
      Liferay 6.0.5 + Icefaces 3.3
    • Assignee Priority:
      P1
    • Salesforce Case Reference:

      Description

      Whenever ace:simpleSelectOneMenu is populated with null as a value, it throws nullpointerexception in the populateList method of the SimpleSelectOneMenuRenderer class in the org.icefaces.ace.component.simpleselectonemenu package. This happens because while populating the selectMenu the function call the toString() method which causes nullpointerexception as the value is null for that selectitem.
      The complete stacktrace for this error is,

      15:57:53,803 ERROR [jsp:154] java.lang.NullPointerException
      at org.icefaces.ace.component.simpleselectonemenu.SimpleSelectOneMenuRenderer.populateList(SimpleSelectOneMenuRenderer.java:172)
      at org.icefaces.ace.component.simpleselectonemenu.SimpleSelectOneMenuRenderer.encodeBegin(SimpleSelectOneMenuRenderer.java:115)
      at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:820)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:333)
      at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:191)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:335)
      at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:79)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:335)
      at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:191)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:335)
      at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:79)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:335)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:342)
      at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:79)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:335)

      I need the null values as the other values for the selectmenu is populated by an enum and null values indicates an sort of 'None' option without which i will have to add it in the enum which will make the enum inconsistent with business logic. This error was NOT present in ice:selectOneMenu component which helped in having a similar implementation for 'None' values.

        Issue Links

          Activity

          Hide
          Max Temp added a comment - - edited

          please test the attached patch

          Show
          Max Temp added a comment - - edited please test the attached patch
          Hide
          Arturo Zambrano added a comment -

          Thank you for offering a patch. The code suggestions have been noted, and the getConvertedValue() method will be refactored in the same way we refactored the same method in the ace:autoCompleteEntry renderer. Note that we cannot use com.sun.faces.* classes; we have to use the API javax.faces.* in order to support both Mojarra and MyFaces.

          Show
          Arturo Zambrano added a comment - Thank you for offering a patch. The code suggestions have been noted, and the getConvertedValue() method will be refactored in the same way we refactored the same method in the ace:autoCompleteEntry renderer. Note that we cannot use com.sun.faces.* classes; we have to use the API javax.faces.* in order to support both Mojarra and MyFaces.
          Hide
          Arturo Zambrano added a comment -

          The challenge with supporting null values in select items is that we have to render the 'value' attribute of the <option> element. There's no way to indicate that the value is null. The value of the <select> element is sent as a string, just like all other input elements, so the closest thing to a null value is an empty string, but we would have to distinguish between a null value and an actual empty string.

          I made some changes locally to support null values. What I did was to avoid rendering the 'value' attribute of the <option> element when the value is null. As expected, when decoding the request, there's no submitted value, so it is regarded as null. However, validation will always fail because the submitted value has to be found in the nested SelectItem's. So, it would make more sense in JSF to simply include a 'None' option or an empty string option and regard it as a no-selection value in the application.

          The reason why there's no NPE exception in ace:selectMenu is that we don't call methods on the value variable (which is null) and we simply pass it to the writer, which will render the string "null", literally. In ace:simpleSelectOneMenu we call .toString() on the null value, and that causes the exception.

          So, we have two options to handle null-values SelectItem's:
          1. Render the "null" string in the 'value' attribute of the <option> element.
          2. Avoid rendering the 'value' attribute in the <option> element, and regard the submitted value as null, but validation will fail.

          Another thing that can be done at the application level is to simply add a button that will directly set the value of the menu property in the bean to null, without having the menu component go through validation.

          Show
          Arturo Zambrano added a comment - The challenge with supporting null values in select items is that we have to render the 'value' attribute of the <option> element. There's no way to indicate that the value is null. The value of the <select> element is sent as a string, just like all other input elements, so the closest thing to a null value is an empty string, but we would have to distinguish between a null value and an actual empty string. I made some changes locally to support null values. What I did was to avoid rendering the 'value' attribute of the <option> element when the value is null. As expected, when decoding the request, there's no submitted value, so it is regarded as null. However, validation will always fail because the submitted value has to be found in the nested SelectItem's. So, it would make more sense in JSF to simply include a 'None' option or an empty string option and regard it as a no-selection value in the application. The reason why there's no NPE exception in ace:selectMenu is that we don't call methods on the value variable (which is null) and we simply pass it to the writer, which will render the string "null", literally. In ace:simpleSelectOneMenu we call .toString() on the null value, and that causes the exception. So, we have two options to handle null-values SelectItem's: 1. Render the "null" string in the 'value' attribute of the <option> element. 2. Avoid rendering the 'value' attribute in the <option> element, and regard the submitted value as null, but validation will fail. Another thing that can be done at the application level is to simply add a button that will directly set the value of the menu property in the bean to null, without having the menu component go through validation.
          Hide
          Arturo Zambrano added a comment -

          What h:selectOneMenu does when the SelectItem value is null is to render the 'value' attribute in <option> with the empty string, and the value that the component takes when the form is submitted is the empty string as well. So, in Mojarra JSF, null equals the empty string.

          Show
          Arturo Zambrano added a comment - What h:selectOneMenu does when the SelectItem value is null is to render the 'value' attribute in <option> with the empty string, and the value that the component takes when the form is submitted is the empty string as well. So, in Mojarra JSF, null equals the empty string.
          Hide
          Arturo Zambrano added a comment -

          Committed fix to trunk at revision 37816. There won't be NPE's when rendering null-valued SelectItem's. Also added support for the "javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL" parameter. It will be necessary to set this parameter to true in order to work with null-values SelectItem's:

          <context-param>
              <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
              <param-value>true</param-value>
          </context-param>
          
          Show
          Arturo Zambrano added a comment - Committed fix to trunk at revision 37816. There won't be NPE's when rendering null-valued SelectItem's. Also added support for the "javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL" parameter. It will be necessary to set this parameter to true in order to work with null-values SelectItem's: <context-param> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name> <param-value>true</param-value> </context-param>
          Hide
          Ken Fyten added a comment -

          Re-open to have this fix applied to the 3.3. maintenance branch also.

          Show
          Ken Fyten added a comment - Re-open to have this fix applied to the 3.3. maintenance branch also.
          Hide
          Judy Guglielmin added a comment -

          backported to ICEFaces-3.3.0 maintenance branch rev 38249

          Show
          Judy Guglielmin added a comment - backported to ICEFaces-3.3.0 maintenance branch rev 38249
          Hide
          Judy Guglielmin added a comment -

          commit was not complete

          Show
          Judy Guglielmin added a comment - commit was not complete
          Hide
          Judy Guglielmin added a comment -

          rev. 41002

          Show
          Judy Guglielmin added a comment - rev. 41002
          Hide
          Liana Munroe added a comment -

          Confirmed resolved Icefaces ee-3.3.0 maintenance branch r41003. Tomcat 6, 7, all browsers.

          Show
          Liana Munroe added a comment - Confirmed resolved Icefaces ee-3.3.0 maintenance branch r41003. Tomcat 6, 7, all browsers.

            People

            • Assignee:
              Judy Guglielmin
              Reporter:
              Viveganandan Nadar
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: