ICEfaces
  1. ICEfaces
  2. ICE-1126

Required Attribute not Working on ice:SelectOneMenu Initialized to Empty String

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.1
    • Fix Version/s: 1.6DR#6, 1.6
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      Operating System: Windows XP
      Platform: PC

      Description

      The Wells-Fargo demo located at repo\applications\wells-fargo has an
      ice:selectOneMenu used to select the U.S. State. Currently, it defaults to
      the first state, but we would like it to have an initial value of nothing with
      the required="true" attribute on the component to force someone to select a
      state.

      At this point in time, adding an initial SelectItem with the value of an empty
      String will not fire the required="true" validator and initializing the first
      SelectItem to nothing will give it a null value and fire a ValidationError:
      Value is not valid.

      For testing purposes, you can add an initial entry with an empty String to the
      application by going to the Criteria class, removing the current
      initialization of the US_STATE_LIST and adding these two lines to the static
      block:

              US_STATE_LIST = new ArrayList(LocationLists.getUsStatesListSize()+1);
              US_STATE_LIST.add(0,new SelectItem(""));

      What we would like to do is add an empty initial SelectItem that would then
      fire the required="true" validator on the component. Please refer to ICE-873
      which was previously supposed to have resolved this issue.

        Activity

        Hide
        Neil Griffin added a comment -

        I am experiencing the same problem with 1.5.3.

        To be more precise, I'm building my select item list like this:

        ArrayList<SelectItem> selectItemList = new ArrayList<SelectItem>();
        selectItemList.add(new SelectItem("", "-- Select --"));

        Now, this generates HTML that looks like this:
        <select>
        <option value="">-- Select --</option>
        </select>

        When the user does not select an item from the list (leaves it as "-- Select -"), the com.icesoft.faces.component.ext.HtmlSelectOneMenu.validate(FacesContext facesContext) method calls the UIInput.getSubmittedValue() method, which, rather than returning an empty string (""), returns "- Select -"!!! This is the heart of the problem. Perhaps it is the ICEfaces partial-submit system passing "- Select --" as a request parameter value. I don't know.

        The reason why the "Validation Error: Value is not valid" message is happening, is because the HtmlSelectOneMenu.validate() sees "-- Select -" instead of an empty string for the submitted value, and then lets the UISelectOne superclass handle it. The superclass does not see "- Select --" as a valid value in the selectitems, and so adds a javax.faces.component.UISelectOne.INVALID message to the validation error list, the English version of which is "Validation Error: Value is not valid"

        – Neil

        Show
        Neil Griffin added a comment - I am experiencing the same problem with 1.5.3. To be more precise, I'm building my select item list like this: ArrayList<SelectItem> selectItemList = new ArrayList<SelectItem>(); selectItemList.add(new SelectItem("", "-- Select --")); Now, this generates HTML that looks like this: <select> <option value="">-- Select --</option> </select> When the user does not select an item from the list (leaves it as "-- Select - "), the com.icesoft.faces.component.ext.HtmlSelectOneMenu.validate(FacesContext facesContext) method calls the UIInput.getSubmittedValue() method, which, rather than returning an empty string (""), returns " - Select - "!!! This is the heart of the problem. Perhaps it is the ICEfaces partial-submit system passing " - Select --" as a request parameter value. I don't know. The reason why the "Validation Error: Value is not valid" message is happening, is because the HtmlSelectOneMenu.validate() sees "-- Select - " instead of an empty string for the submitted value, and then lets the UISelectOne superclass handle it. The superclass does not see " - Select --" as a valid value in the selectitems, and so adds a javax.faces.component.UISelectOne.INVALID message to the validation error list, the English version of which is "Validation Error: Value is not valid" – Neil
        Hide
        Adnan Durrani added a comment -

        We verified Neil's finding that the value sent by the browser is "-- Select --" instead of "". Mircea is working on it.

        Show
        Adnan Durrani added a comment - We verified Neil's finding that the value sent by the browser is "-- Select --" instead of "". Mircea is working on it.
        Hide
        Mircea Toma added a comment -

        Fix <select> element's serialization when the value is the empty string.

        Show
        Mircea Toma added a comment - Fix <select> element's serialization when the value is the empty string.
        Hide
        Adnan Durrani added a comment -

        Mircea's check-in fixes this bug. I have re-tested above issues and it works fine now.

        Show
        Adnan Durrani added a comment - Mircea's check-in fixes this bug. I have re-tested above issues and it works fine now.
        Hide
        Philip Breau added a comment -

        The required attribute is not working when contained in a UIData component. Please see https://www.icesoft.ca:4443/supportilla/show_bug.cgi?id=4030 for more details.

        Show
        Philip Breau added a comment - The required attribute is not working when contained in a UIData component. Please see https://www.icesoft.ca:4443/supportilla/show_bug.cgi?id=4030 for more details.
        Hide
        Philip Breau added a comment -

        ignore last comment

        Show
        Philip Breau added a comment - ignore last comment
        Hide
        Neil Griffin added a comment -

        This is an enhanced version of the sample portlet released with Liferay 4.3.0-RC1, which has been modified to reproduce this problem.

        Show
        Neil Griffin added a comment - This is an enhanced version of the sample portlet released with Liferay 4.3.0-RC1, which has been modified to reproduce this problem.
        Hide
        Neil Griffin added a comment -

        I still think that this one is broken.

        I just attached an enhanced version of the sample portlet released with Liferay 4.3.0-RC1, which has been modified to reproduce this problem.

        To reproduce:

        • Copy the attached portlet .WAR into $HOME/liferay/deploy (hot deploy folder):
        • Start the portal
        • Add a new portal page named "ICEfaces"
        • Add the Sample ICEfaces (Sun RI) Portlet from the "Add Content" option
        • Hit the Submit button

        Notice that all the required fields except the <ice:selectOneMenu/> are validated properly. In other words, it should have a "Value is Required" error message next to it like all the others.

        --Neil

        Show
        Neil Griffin added a comment - I still think that this one is broken. I just attached an enhanced version of the sample portlet released with Liferay 4.3.0-RC1, which has been modified to reproduce this problem. To reproduce: Download Liferay 4.3.0-RC1 from here and install: http://www.liferay.com/web/guest/downloads/liferay_enterprise_portal/4_3_0rc1 Copy the attached portlet .WAR into $HOME/liferay/deploy (hot deploy folder): Start the portal Start Browser and visit http://localhost:8080 and login as test@liferay.com with password test Add a new portal page named "ICEfaces" Add the Sample ICEfaces (Sun RI) Portlet from the "Add Content" option Hit the Submit button Notice that all the required fields except the <ice:selectOneMenu/> are validated properly. In other words, it should have a "Value is Required" error message next to it like all the others. --Neil
        Hide
        Neil Griffin added a comment -

        Forgot to mention that I don't think this is a portlet issue. I think it would be reproducable in a webapp environment as well. The only example I have is a portlet example though (attached).

        --Neil

        Show
        Neil Griffin added a comment - Forgot to mention that I don't think this is a portlet issue. I think it would be reproducable in a webapp environment as well. The only example I have is a portlet example though (attached). --Neil
        Hide
        Ken Fyten added a comment -

        Can you retest to ensure that selectOneMenu required is working as expected in 1.6 trunk.

        Show
        Ken Fyten added a comment - Can you retest to ensure that selectOneMenu required is working as expected in 1.6 trunk.
        Hide
        Brad Kroeger added a comment -

        I tested with the wells-fargo demo app and using "" as the value of the first item will fire the required validator. Not entering "" and leaving the item value as null will produce "null" as the first item in the UI.

        However, after interacting with the other input components you are able to get through (without another "required" message showing up) without changing the selection to a valid value.

        Show
        Brad Kroeger added a comment - I tested with the wells-fargo demo app and using "" as the value of the first item will fire the required validator. Not entering "" and leaving the item value as null will produce "null" as the first item in the UI. However, after interacting with the other input components you are able to get through (without another "required" message showing up) without changing the selection to a valid value.
        Hide
        Neil Griffin added a comment -

        I just tried this again with the latest trunk and the required validator is not firing.

        In my managed bean, I populate the list like this:

        ArrayList listItems = new ArrayList();
        listItems.add(new SelectItem("", "-- Select --");

        The rendered HTML looks like this:

        <option value="">-- Select --</option>

        The required validator is not firing when I tab out of the field, and is not firing when I submit the form.

        Please advise – Thanks!

        Neil

        Show
        Neil Griffin added a comment - I just tried this again with the latest trunk and the required validator is not firing. In my managed bean, I populate the list like this: ArrayList listItems = new ArrayList(); listItems.add(new SelectItem("", "-- Select --"); The rendered HTML looks like this: <option value="">-- Select --</option> The required validator is not firing when I tab out of the field, and is not firing when I submit the form. Please advise – Thanks! Neil
        Hide
        Adnan Durrani added a comment -

        Hi Brad and Neil,

        I have checked-in a fix for the above issue, can you guys please verify if it has been fixed. revision 14237

        Thanks,

        Show
        Adnan Durrani added a comment - Hi Brad and Neil, I have checked-in a fix for the above issue, can you guys please verify if it has been fixed. revision 14237 Thanks,
        Hide
        Brad Kroeger added a comment -

        I have tested this agains the wells-fargo demo and it appears to be working.

        Show
        Brad Kroeger added a comment - I have tested this agains the wells-fargo demo and it appears to be working.
        Hide
        Adnan Durrani added a comment -

        As Brad verified it. I am resolving this case.

        Show
        Adnan Durrani added a comment - As Brad verified it. I am resolving this case.

          People

          • Assignee:
            Unassigned
            Reporter:
            Brad Kroeger
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: