Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Won't Fix
    • Affects Version/s: 1.1, 1.2, 2.0, 2.1
    • Fix Version/s: None
    • Component/s: EL
    • Labels:
      None

      Description

      This is a copy of issue http://java.net/jira/browse/UEL-7. This issue already has a proposed patch.

      Text as in UEL-7:
      --------------------------------[ begin ]--------------------------------
      When we have a class like:

      public class GenericsTestController<E extends Object> {

      private E value;

      public E getValue()

      { return value; }

      public void setValue(E value)

      { this.value = value; }

      }

      And we have this class to use as a managed bean (integerTest):
      public class IntegerTestController extends GenericsTestController<Integer> {

      public String add()

      { setValue(getValue()+1); return null; }

      public String subtract()

      { setValue(getValue()-1); return null; }

      }

      This JSF code will not work:
      <h:form>
      Value:
      <h:inputText value="#

      {integerTest.value}

      " />
      <h:commandButton action="#

      {integerTest.add}

      " value="+" />
      <h:commandButton action="#

      {integerTest.subtract}

      " value="-" />
      </h:form>

      With this error:
      java.lang.ClassCastException: java.lang.String cannot be cast to Java.lang.Integer at genericstest.IntegerTestController.add(IntegerTestController.java:18)

      The problem is with section 2.2.7 of the specification (1.1):

      "The provided property will first be coerced to a String. If there is a BeanInfoProperty for this property and there were no errors retrieving it, the propertyType of the propertyDescriptor is returned. Otherwise, a PropertyNotFoundException is thrown."

      The propertyType of a generic property is Object.class, that gets coerced to String.class, and we get the ClassCastException.
      --------------------------------[ end ]--------------------------------

        Activity

        Hide
        Ed Burns added a comment -

        Use CDI instead.

        Show
        Ed Burns added a comment - Use CDI instead.
        Hide
        Ed Burns added a comment -

        Set priority to baseline ahead of JSF 2.3 triage. Priorities will be assigned accurately after this exercise.

        Show
        Ed Burns added a comment - Set priority to baseline ahead of JSF 2.3 triage. Priorities will be assigned accurately after this exercise.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: