ICEfaces
  1. ICEfaces
  2. ICE-8282

ice:selectOneMenu - valueChangeListener called when no value has changed

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: EE-1.8.2.GA_P04
    • Fix Version/s: EE-1.8.2.GA_P05
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      All
    • Assignee Priority:
      P1
    • Workaround Exists:
      Yes
    • Workaround Description:
      Hide
      Don't use an empty string, instead use any other sentinel value. A space works:

      <f:selectItem itemValue=" " itemLabel="-" />
      private String a = " ";
      Show
      Don't use an empty string, instead use any other sentinel value. A space works: <f:selectItem itemValue=" " itemLabel="-" /> private String a = " ";

      Description

      In a simple test case an ice:selectOneMenu is shown on the page. A command button is set to submit the form. If the page is loaded and button clicked without changing the value of the menu, the valueChangeListener is called.

      When the value change listener is called, the getNewValue() method returns null instead of an empty string which it is initialized to.

        Activity

        Hide
        Arran Mccullough added a comment -

        Attached Test case that shows issue.

        Steps:

        • Load welcomeICEfaces.iface
        • Click on the submit button, in the logs it will show the VCL being called and a null value return for the getNewValue()
        Show
        Arran Mccullough added a comment - Attached Test case that shows issue. Steps: Load welcomeICEfaces.iface Click on the submit button, in the logs it will show the VCL being called and a null value return for the getNewValue()
        Hide
        Mircea Toma added a comment - - edited

        It looks like MenuRenderer.getConvertedValue(...) converts an empty string submitted value to a null. This method is called during validation.

        if (uiComponent instanceof UISelectOne) {
        if (newSubmittedValue == null || "".equals(newSubmittedValue))

        { return null; }

        else {
        .....

        I don't know what is the expected behavior but it seems to me that empty strings should not be changed to null values since the MenuRenderer is already using empty strings in its decode method.

        Changing MenuRenderer.getConvertedValue(...) to avoid converting empty strings solves this issue.

        Show
        Mircea Toma added a comment - - edited It looks like MenuRenderer.getConvertedValue(...) converts an empty string submitted value to a null. This method is called during validation. if (uiComponent instanceof UISelectOne) { if (newSubmittedValue == null || "".equals(newSubmittedValue)) { return null; } else { ..... I don't know what is the expected behavior but it seems to me that empty strings should not be changed to null values since the MenuRenderer is already using empty strings in its decode method. Changing MenuRenderer.getConvertedValue(...) to avoid converting empty strings solves this issue.
        Hide
        Mark Collette added a comment -

        With HTML forms, a lack of data entered is frequently submitted as:

        form_field_name=

        which means that it doesn't differentiate between no input and a string with no length. With select + option elements, we have the same issue where when an option has selected=selected, then the select is submitted as it's name = the selected option's value. If that option happens to have a value of a string with no length, then it's indistinguishable from no selection happening. As such, a string with no length is effectively a reserved sentinel value for no selection, and it's not proper application usage to take that value and re-use it for something else. In this case, the application is using it to indicate a selection of an option which it internally deems as a non-user-choice. We need to take care to avoid confusing non-selection and non-user-choice.

        To fix this, we need to make use of another sentinel value to indicate this non-user-choice. Anything will do, and I have tested that a space works fine. I changed the selectItem thusly:

        <f:selectItem itemValue=" " itemLabel="-" />

        And also, we need to change what the bean property is initialised to, or else we'll still get a single errant ValueChangeEvent.

        private String a = " ";

        Show
        Mark Collette added a comment - With HTML forms, a lack of data entered is frequently submitted as: form_field_name= which means that it doesn't differentiate between no input and a string with no length. With select + option elements, we have the same issue where when an option has selected=selected, then the select is submitted as it's name = the selected option's value. If that option happens to have a value of a string with no length, then it's indistinguishable from no selection happening. As such, a string with no length is effectively a reserved sentinel value for no selection, and it's not proper application usage to take that value and re-use it for something else. In this case, the application is using it to indicate a selection of an option which it internally deems as a non-user-choice. We need to take care to avoid confusing non-selection and non-user-choice. To fix this, we need to make use of another sentinel value to indicate this non-user-choice. Anything will do, and I have tested that a space works fine. I changed the selectItem thusly: <f:selectItem itemValue=" " itemLabel="-" /> And also, we need to change what the bean property is initialised to, or else we'll still get a single errant ValueChangeEvent. private String a = " ";

          People

          • Assignee:
            Mircea Toma
            Reporter:
            Arran Mccullough
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: