javaserverfaces-spec-public
  1. javaserverfaces-spec-public
  2. JAVASERVERFACES_SPEC_PUBLIC-745

Type of #{cc.attrs.test} cannot be obtained if test resolves to null

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.2
    • Component/s: EL
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      745
    • Status Whiteboard:
      Hide

      cat1 frame size_small importance_medium

      Show
      cat1 frame size_small importance_medium

      Description

      On a facelets composite component the type of a ValueExpression like
      #

      {cc.attrs.test}

      cannot be obtained if the property test resolves to null,
      because #

      {cc.attrs} resolves to a Map and thus the MapELResolver is used to
      determine the type. However this resolver can only determine the type if the
      value is not null.

      This can lead to problems with composite components with EditableValueHolders on
      the first request (when the property in the managed bean is null).

      You can test this with the mojarra sample "switchlistComponent.xhtml" by setting
      the properties list1 and list2 in the managed bean SwitchlistBean from String[]
      to List<String>. This sample currently only works because mojarra uses a
      String[] as the value type of a h:selectManyMenu if the type of the
      ValueExpression resolves to null. When you change the property type to
      List<String> you will get a ClassCastException.

      You won't see this problem if you're using the code from the composite component
      implementation directly in your view, because then you will get the right type
      from the ValueExpression even though it resolves to null and so everything will
      work fine. Therefore this issue is problematic, because it is not easy to track
      down.

      However the solution to it is very simple. Just change the method getType() from
      CompositeComponentELResolver to be aware of the base which is the wrapper for
      the composite's attributes (#{cc.attrs}

      ) and use getExpression((String)
      property).getType() to determine the right type in that case.

      Please take a look at the related MyFaces issue MYFACES-2552. I already provided
      a very simple patch to solve this problem.

      1. 20110720_i_spec_745.patch
        8 kB
        Ed Burns
      2. changebundle.txt
        32 kB
        Matt Benson
      3. changebundle.txt
        32 kB
        Matt Benson
      4. changebundle.txt
        20 kB
        Ed Burns
      5. changebundle.txt
        15 kB
        Ed Burns
      6. changebundle.txt
        20 kB
        Ed Burns

        Activity

        Hide
        Matt Benson added a comment - - edited

        update to tests: rename *string attributes *literal and exercise typedXliteral using type="java.lang.Integer" per suggestion of Imre Oßwald

        Show
        Matt Benson added a comment - - edited update to tests: rename *string attributes *literal and exercise typedXliteral using type="java.lang.Integer" per suggestion of Imre Oßwald
        Hide
        Ed Burns added a comment -

        New patch from Matt and Imre.

        Show
        Ed Burns added a comment - New patch from Matt and Imre.
        Hide
        Ed Burns added a comment -

        Sending jsf-ri/src/main/java/com/sun/faces/el/CompositeComponentAttributesELResolver.java
        Sending jsf-ri/test/com/sun/faces/application/resource/TestResourceHandlerImpl.java
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/build.xml
        Adding jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/java/com/sun/faces/regression/i_spec_745_war/GetTestType.java
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/java/com/sun/faces/regression/i_spec_745_war/JavaTopLevelComponent.java
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/java/com/sun/faces/regression/i_spec_745_war/UserBean.java
        Adding jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/i_spec_745.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/i_spec_745_1.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/i_spec_745_2.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/i_spec_745_3.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/i_spec_745_4.xhtml
        Adding jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_1.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_2.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_3.xhtml
        Sending jsf-test/JAVASERVERFACES_SPEC_PUBLIC-745/i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_4.xhtml
        Transmitting file data ................
        Committed revision 9246.
        committed to trunk.

        Show
        Ed Burns added a comment - Sending jsf-ri/src/main/java/com/sun/faces/el/CompositeComponentAttributesELResolver.java Sending jsf-ri/test/com/sun/faces/application/resource/TestResourceHandlerImpl.java Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /build.xml Adding jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/java/com/sun/faces/regression/i_spec_745_war/GetTestType.java Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/java/com/sun/faces/regression/i_spec_745_war/JavaTopLevelComponent.java Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/java/com/sun/faces/regression/i_spec_745_war/UserBean.java Adding jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/i_spec_745.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/i_spec_745_1.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/i_spec_745_2.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/i_spec_745_3.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/i_spec_745_4.xhtml Adding jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_1.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_2.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_3.xhtml Sending jsf-test/ JAVASERVERFACES_SPEC_PUBLIC-745 /i_spec_745_war/src/main/webapp/resources/ezcomp/i_spec_745_cc_4.xhtml Transmitting file data ................ Committed revision 9246. committed to trunk.
        Hide
        Ed Burns added a comment -

        Sending preface.fm
        Sending valueReferences.fm
        Transmitting file data ..
        Committed revision 1026.

        Rhombus:frame edburns$ cat changebundle.txt
        Further tweaks and optimizations http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-745

        SECTION: Modified Files
        ----------------------------
        M valueReferences.fm

        • New spec for getType().

        If the base argument to getType() is not an instance of the composite
        component attributes map or the property argument to getType() is not
        an instance of java.lang.String, return null. Otherwise, check the
        top level component's ValueExpression collection for an expression
        under the name given by the property argument to getType(). If the
        expression exists, call getType() on the expression. If the property
        argument to getType() is not empty, search the composite component's
        metadata for a declared type on a <composite:attribute> whose name
        matches the property argument to getType(). If the expression and the
        metadata both yield results, the metadata takes precedence ONLY if it
        provides a narrower result than does the expression, i.e. expression
        type is assignable from metadata type. If the metadata result does
        take precedence, call ELContext.setPropertyResolved(true). Otherwise,
        return whichever result was available, or null.

        M preface.fm

        • point to new changes.
        Show
        Ed Burns added a comment - Sending preface.fm Sending valueReferences.fm Transmitting file data .. Committed revision 1026. Rhombus:frame edburns$ cat changebundle.txt Further tweaks and optimizations http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-745 SECTION: Modified Files ---------------------------- M valueReferences.fm New spec for getType(). If the base argument to getType() is not an instance of the composite component attributes map or the property argument to getType() is not an instance of java.lang.String, return null. Otherwise, check the top level component's ValueExpression collection for an expression under the name given by the property argument to getType(). If the expression exists, call getType() on the expression. If the property argument to getType() is not empty, search the composite component's metadata for a declared type on a <composite:attribute> whose name matches the property argument to getType(). If the expression and the metadata both yield results, the metadata takes precedence ONLY if it provides a narrower result than does the expression, i.e. expression type is assignable from metadata type. If the metadata result does take precedence, call ELContext.setPropertyResolved(true). Otherwise, return whichever result was available, or null. M preface.fm point to new changes.
        Hide
        Manfred Riem added a comment -

        Closing resolved issue out

        Show
        Manfred Riem added a comment - Closing resolved issue out

          People

          • Assignee:
            Ed Burns
            Reporter:
            Jakob Korherr
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 2 days
              2d
              Remaining:
              Time Spent - 5 hours Remaining Estimate - 1 day, 19 hours
              1d 19h
              Logged:
              Time Spent - 5 hours Remaining Estimate - 1 day, 19 hours
              5h