MyFaces Core
  1. MyFaces Core
  2. MYFACES-2006

getTableIndex: Integer to String (ClassCastException)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.6
    • Fix Version/s: 1.1.8
    • Component/s: None
    • Labels:
      None

      Description

      Have a project using MyFaces 1.1.5 and Tomahawk 1.1.7. When MyFaces 1.1.5 is upgraded to 1.1.6 classcast exceptions are thrown when elements such as HtmlInputText try to access getTabIndex through an EL expression that returns an "int". Though the spec states that the EL expression should return a string, this was not a problem in the previous version. If tag attributes are more strict in the latest release, it would help to have stated so in the release notes.

        Activity

        Hide
        Leonardo Uribe added a comment -

        If the ValueBinding returns null, it should return null, otherwise call on this value toString();

        Show
        Leonardo Uribe added a comment - If the ValueBinding returns null, it should return null, otherwise call on this value toString();
        Hide
        Leonardo Uribe added a comment -

        Patch to be applied on core and tomahawk. Note that this only applies by backward compatibility (previous jsf 1.1 core and tomahawk versions behaves like described). So, on jsf 1.2 related branches this should never be applied and changes should be made on applications.

        If no objections I'll commit this patch.

        Show
        Leonardo Uribe added a comment - Patch to be applied on core and tomahawk. Note that this only applies by backward compatibility (previous jsf 1.1 core and tomahawk versions behaves like described). So, on jsf 1.2 related branches this should never be applied and changes should be made on applications. If no objections I'll commit this patch.
        Hide
        Taro App added a comment -

        I have voted for this issue. This is more serious for me. The problem is not just inputText's tabindex, but more wide spread. For example,

        • binding for inputText's size and maxlength must be an Integer and not null.
        • binding for inputText's tabindex must be a String and not null.
        • binding for inputText's disabled and readonly must not return null.
        • binding for inputTextarea's rows and cols must be an Integer and not null.
        • binding for graphicsImage's width and height must be a String and not null.

        Firstly, it does not seem consistent. For example, inputText's size is an Integer, where graphicsImage's width is a String. If a value binding does not return matching data type, ClassCastException is thrown. In the previous releases, it just worked.
        Secondly, it does not default. If a value binding returns null, NullPointerException is thrown. In the previous releases, default value is used instead.
        Thirdly, arithmatic expression binding cannot be used. For example, setting size="#

        {bean.value * 10}

        " for inputText raises ClassCastExpression because the calculated value is a Long.

        I have a large application which has been working on MyFaces Core 1.1.3 and Tomahawk 1.1.3. I am trying to upgrade to MyFaces Core 1.1.6 and Tomahawk 1.1.7, but this is the blocking issue.

        Show
        Taro App added a comment - I have voted for this issue. This is more serious for me. The problem is not just inputText's tabindex, but more wide spread. For example, binding for inputText's size and maxlength must be an Integer and not null. binding for inputText's tabindex must be a String and not null. binding for inputText's disabled and readonly must not return null. binding for inputTextarea's rows and cols must be an Integer and not null. binding for graphicsImage's width and height must be a String and not null. Firstly, it does not seem consistent. For example, inputText's size is an Integer, where graphicsImage's width is a String. If a value binding does not return matching data type, ClassCastException is thrown. In the previous releases, it just worked. Secondly, it does not default. If a value binding returns null, NullPointerException is thrown. In the previous releases, default value is used instead. Thirdly, arithmatic expression binding cannot be used. For example, setting size="# {bean.value * 10} " for inputText raises ClassCastExpression because the calculated value is a Long. I have a large application which has been working on MyFaces Core 1.1.3 and Tomahawk 1.1.3. I am trying to upgrade to MyFaces Core 1.1.6 and Tomahawk 1.1.7, but this is the blocking issue.
        Hide
        Paris Holley added a comment -

        Indeed, this does not appear to be a blocker issue.

        So the best solution I would assume (on my end), is to return an Integer instead of a String (so that there are no conflicts), however the question you present is an interesting dilemma.

        In my opinion, introducing "new standards" within the JSF 1.1 releases wouldn't seem appropriate given that it is an older version and it has been used since the MyFaces 1.0.x releases. I am always for standards (which surely should be put in place on JSF 1.2), however I think that at some point backwards compatibility is just as important (particularly if you consider the 1.0.x releases a "legacy" library).

        Show
        Paris Holley added a comment - Indeed, this does not appear to be a blocker issue. So the best solution I would assume (on my end), is to return an Integer instead of a String (so that there are no conflicts), however the question you present is an interesting dilemma. In my opinion, introducing "new standards" within the JSF 1.1 releases wouldn't seem appropriate given that it is an older version and it has been used since the MyFaces 1.0.x releases. I am always for standards (which surely should be put in place on JSF 1.2), however I think that at some point backwards compatibility is just as important (particularly if you consider the 1.0.x releases a "legacy" library).
        Hide
        Leonardo Uribe added a comment -

        The original code looks like this:

        public String getTabindex()

        { if (_tabindex != null) return _tabindex; ValueBinding vb = getValueBinding("tabindex"); return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null; }

        and the method getStringValue looks like this:

        static String getStringValue(FacesContext context, ValueBinding vb)
        {
        Object value = vb.getValue(context);
        if(value == null)

        { return null; }

        return value.toString();
        }

        The effect described here comes from the use of value.toString(). If receives a EL expression that returns something different to String (in this case Integer) the effect of toString() is convert the value, so the component can handle it correctly.

        The introduction of component generation using myfaces-builder-plugin, introduce without notice the change described. (It's more, there was a release candidate for 1.1.6 release before the real release) . In fact, this is not a blocker issue, because there exists a valid solution for that (change signature on the bean to return String instead). In jsf 1.2, this behavior is not present so when you go from 1.1 to 1.2 the same problem occur.

        Here comes the difficult part: If in jsf 1.2 this behavior is not present, but on previous jsf 1.1 myfaces releases this is valid, Should we change this on 1.1?

        If no objections I'll lower the priority of this issue to major.

        Show
        Leonardo Uribe added a comment - The original code looks like this: public String getTabindex() { if (_tabindex != null) return _tabindex; ValueBinding vb = getValueBinding("tabindex"); return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null; } and the method getStringValue looks like this: static String getStringValue(FacesContext context, ValueBinding vb) { Object value = vb.getValue(context); if(value == null) { return null; } return value.toString(); } The effect described here comes from the use of value.toString(). If receives a EL expression that returns something different to String (in this case Integer) the effect of toString() is convert the value, so the component can handle it correctly. The introduction of component generation using myfaces-builder-plugin, introduce without notice the change described. (It's more, there was a release candidate for 1.1.6 release before the real release) . In fact, this is not a blocker issue, because there exists a valid solution for that (change signature on the bean to return String instead). In jsf 1.2, this behavior is not present so when you go from 1.1 to 1.2 the same problem occur. Here comes the difficult part: If in jsf 1.2 this behavior is not present, but on previous jsf 1.1 myfaces releases this is valid, Should we change this on 1.1? If no objections I'll lower the priority of this issue to major.

          People

          • Assignee:
            Leonardo Uribe
            Reporter:
            Paris Holley
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development