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

          Viveganandan Nadar created issue -
          Hide
          Max Temp added a comment - - edited

          please test the attached patch

          Show
          Max Temp added a comment - - edited please test the attached patch
          Max Temp made changes -
          Field Original Value New Value
          Attachment SimpleSelectOneMenuRenderer.diff [ 16190 ]
          Max Temp made changes -
          Attachment SimpleSelectOneMenuRenderer.diff [ 16190 ]
          Max Temp made changes -
          Attachment SimpleSelectOneMenuRenderer.diff [ 16192 ]
          Arran Mccullough made changes -
          Salesforce Case Reference 5007000000VHtDmAAL
          Ken Fyten made changes -
          Assignee Arturo Zambrano [ artzambrano ]
          Fix Version/s EE-3.3.0.GA_P01 [ 11174 ]
          Fix Version/s 3.4 [ 10770 ]
          Assignee Priority P1 [ 10010 ]
          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.
          Ken Fyten made changes -
          Fix Version/s EE-3.3.0.GA_P01 [ 11174 ]
          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.
          Arturo Zambrano made changes -
          Link This issue depends on ICE-9560 [ ICE-9560 ]
          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>
          Arturo Zambrano made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #37816 Fri Sep 06 17:17:14 MDT 2013 art.zambrano ICE-9385 fix to prevent NPE's when rendering null values as option items; added support for javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL parameter, making component behave like h:selectOneMenu
          Files Changed
          Commit graph MODIFY /icefaces3/trunk/icefaces/ace/component/src/org/icefaces/ace/component/simpleselectonemenu/SimpleSelectOneMenuRenderer.java
          Ken Fyten made changes -
          Summary NullPointerException in ace:simpleSelectOneMenu ace:simpleSelectOneMenu - Support 'javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL' (was NullPointerException in ace:simpleSelectOneMenu)
          Judy Guglielmin made changes -
          Link This issue blocks ICE-10008 [ ICE-10008 ]
          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.
          Ken Fyten made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Ken Fyten made changes -
          Fix Version/s EE-3.3.0.GA_P02 [ 11371 ]
          Ken Fyten made changes -
          Assignee Arturo Zambrano [ artzambrano ] Judy Guglielmin [ judy.guglielmin ]
          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
          Judy Guglielmin made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          Judy Guglielmin added a comment -

          commit was not complete

          Show
          Judy Guglielmin added a comment - commit was not complete
          Judy Guglielmin made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Hide
          Judy Guglielmin added a comment -

          rev. 41002

          Show
          Judy Guglielmin added a comment - rev. 41002
          Judy Guglielmin made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          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.
          Ken Fyten made changes -
          Fix Version/s 4.0 [ 11382 ]
          Ken Fyten made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

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

              Dates

              • Created:
                Updated:
                Resolved: