Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7DR#2
    • Fix Version/s: 1.7
    • Component/s: None
    • Labels:
      None
    • Environment:
      Apach 6.0.14, ice 1.7DR2, jsf 1.2.04

      Description

      When users got slectitems with null like:
        <f:selectItem itemValue="" itemLabel="op default" />
        <f:selectItem itemValue="0" itemLabel="op1" />
        <f:selectItem itemValue="1" itemLabel="op2" />

      may see this error:
      java.lang.NumberFormatException: For input string: ""
      java.lang.NumberFormatException.forInputString(Unknown Source)
      java.lang.Integer.parseInt(Unknown Source)
      java.lang.Short.parseShort(Unknown Source)
      java.lang.Short.valueOf(Unknown Source)
      java.lang.Short.valueOf(Unknown Source)
      com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.isConversionMatched(MenuRenderer.java:663)
      com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.isSelected(MenuRenderer.java:469)

      With class version of this list like <f:selectItems> these errors are not occurs.

      I think that this patch should be added to file
      com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.java

      Around line 649-653

          private boolean isConversionMatched(String sentinel, Object selectedValue){
           boolean match = false;
      > if (sentinel!=null && sentinel.length()==0 && selectedValue==null){
      > match = true;
      > } else
           if (selectedValue instanceof Long){
           if (selectedValue.equals(Long.valueOf(sentinel))) {
      1. MenuRenderer.java
        28 kB
        Krashan Brahmanjara

        Activity

        Hide
        Krashan Brahmanjara added a comment -

        On 1.7dr3 and current trunk the same problem and solution will by vaild

        Correct patch

        private boolean isConversionMatched(String sentinel, Object selectedValue){
        boolean match = false;
        > if (sentinel!=null && sentinel.length()==0)

        { > if (selectedValue==null) match = true; > }

        else
        if (selectedValue instanceof Long){

        Alternative code for <f:selectItems> test purpose. Work correct with jsf 1.2.

        list = new ArrayList<SelectItem>();
        list.add( new SelectItem( null ,"op default",""));
        list.add( new SelectItem( new Short((short)0),"op1",""));
        list.add( new SelectItem( new Short((short)1),"op2",""));

        For the future I suggest to remove jsf 1.1 libraries from Icefaces distribution. Libraries from jsf 1.1 got several problems with converters and validators. People thinking there are icefaces problems.

        Show
        Krashan Brahmanjara added a comment - On 1.7dr3 and current trunk the same problem and solution will by vaild Correct patch private boolean isConversionMatched(String sentinel, Object selectedValue){ boolean match = false; > if (sentinel!=null && sentinel.length()==0) { > if (selectedValue==null) match = true; > } else if (selectedValue instanceof Long){ Alternative code for <f:selectItems> test purpose. Work correct with jsf 1.2. list = new ArrayList<SelectItem>(); list.add( new SelectItem( null ,"op default","")); list.add( new SelectItem( new Short((short)0),"op1","")); list.add( new SelectItem( new Short((short)1),"op2","")); For the future I suggest to remove jsf 1.1 libraries from Icefaces distribution. Libraries from jsf 1.1 got several problems with converters and validators. People thinking there are icefaces problems.
        Hide
        Mark Collette added a comment -

        This behaviour exists in stock JSF, so I've posted this to their mailing list, and am awaiting a reply.

        Show
        Mark Collette added a comment - This behaviour exists in stock JSF, so I've posted this to their mailing list, and am awaiting a reply.
        Hide
        Mark Collette added a comment -

        That is, they don't have the NumberFormatException, but when the bean has a null value in the Long getter, it won't make the corresponding empty SelectItem be selected.

        Show
        Mark Collette added a comment - That is, they don't have the NumberFormatException, but when the bean has a null value in the Long getter, it won't make the corresponding empty SelectItem be selected.
        Hide
        Krashan Brahmanjara added a comment -

        My post is about ice:selectOneRadio behaviour and binding beetwen values (not selecting).
        Of course sometimes first "null" item is "default" so it may be not selected.

        My patch eliminate error message and different behavior of these two cases

        Case 1 - this get error

        <ice:selectOneRadio id="e2" styleClass="selectTag"
        <f:selectItem itemValue="" itemLabel="op default" />
        <f:selectItem itemValue="0" itemLabel="op1" />
        <f:selectItem itemValue="1" itemLabel="op2" />
        </>

        Case 2 - this is ok
        <ice:selectOneRadio id="e2" styleClass="selectTag"
        <f:selectItems value="#

        {class.value}

        " /

        class getValue

        { list = new ArrayList<SelectItem>(); list.add( new SelectItem( null ,"op default","")); list.add( new SelectItem( new Short((short)0),"op1","")); list.add( new SelectItem( new Short((short)1),"op2","")); }
        Show
        Krashan Brahmanjara added a comment - My post is about ice:selectOneRadio behaviour and binding beetwen values (not selecting). Of course sometimes first "null" item is "default" so it may be not selected. My patch eliminate error message and different behavior of these two cases Case 1 - this get error <ice:selectOneRadio id="e2" styleClass="selectTag" <f:selectItem itemValue="" itemLabel="op default" /> <f:selectItem itemValue="0" itemLabel="op1" /> <f:selectItem itemValue="1" itemLabel="op2" /> </> Case 2 - this is ok <ice:selectOneRadio id="e2" styleClass="selectTag" <f:selectItems value="# {class.value} " / class getValue { list = new ArrayList<SelectItem>(); list.add( new SelectItem( null ,"op default","")); list.add( new SelectItem( new Short((short)0),"op1","")); list.add( new SelectItem( new Short((short)1),"op2","")); }
        Hide
        Mark Collette added a comment -

        There are implications of your patch, which could deviate ICEfaces from the JSF specification, which need to be addressed. Yes, the NumberFormatException should be fixed, but I'm not sure that your patch is the way to do it. For example, you want
        <f:selectItem itemValue="" itemLabel="op default" />
        to behave like
        list.add( new SelectItem( null ,"op default",""));
        but the itemValue of case 1 is "" (empty String) and the itemValue of case 2 is null. Those are not the same values, so it's not clear to me that they should behave the same.

        Show
        Mark Collette added a comment - There are implications of your patch, which could deviate ICEfaces from the JSF specification, which need to be addressed. Yes, the NumberFormatException should be fixed, but I'm not sure that your patch is the way to do it. For example, you want <f:selectItem itemValue="" itemLabel="op default" /> to behave like list.add( new SelectItem( null ,"op default","")); but the itemValue of case 1 is "" (empty String) and the itemValue of case 2 is null. Those are not the same values, so it's not clear to me that they should behave the same.
        Hide
        Krashan Brahmanjara added a comment -

        True, someone also can say "use converter" but it is not neccesery.

        Values from array of selectItems can contain any Objects and null so f:selectItem can expect similar values.
        Most users will also expect from <ice:selectItems> behaviour similar to <f:selectItems>.

        Show
        Krashan Brahmanjara added a comment - True, someone also can say "use converter" but it is not neccesery. Values from array of selectItems can contain any Objects and null so f:selectItem can expect similar values. Most users will also expect from <ice:selectItems> behaviour similar to <f:selectItems>.
        Hide
        Krashan Brahmanjara added a comment -

        Sorry if this is any duplicate but in MenuRenderer I see not correct usage of trim.
        (package com.icesoft.faces.renderkit.dom_html_basic)

        For "select" values users can bind any value like "test", "test ", "test " any string with spaces (especially Hibernate can get strings with spaces)
        But in line 85 of MenuRenderer.java someone include trim() and returned values are changed and are not the same as rendered before.

        Result of this bug are nulls and validation errors.

        In attachment my patch of above two bugs.

        Show
        Krashan Brahmanjara added a comment - Sorry if this is any duplicate but in MenuRenderer I see not correct usage of trim. (package com.icesoft.faces.renderkit.dom_html_basic) For "select" values users can bind any value like "test", "test ", "test " any string with spaces (especially Hibernate can get strings with spaces) But in line 85 of MenuRenderer.java someone include trim() and returned values are changed and are not the same as rendered before. Result of this bug are nulls and validation errors. In attachment my patch of above two bugs.
        Hide
        Krashan Brahmanjara added a comment -

        Working patch of space and nulls problem.

        Show
        Krashan Brahmanjara added a comment - Working patch of space and nulls problem.
        Hide
        Mark Collette added a comment -

        I checked the EL type conversion rules, and your patch suggestion is consistent with that.

        Subversion 16101
        icefaces\core\src\com\icesoft\faces\renderkit\dom_html_basic\MenuRenderer.java

        Show
        Mark Collette added a comment - I checked the EL type conversion rules, and your patch suggestion is consistent with that. Subversion 16101 icefaces\core\src\com\icesoft\faces\renderkit\dom_html_basic\MenuRenderer.java

          People

          • Assignee:
            Unassigned
            Reporter:
            Krashan Brahmanjara
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: