Click
  1. Click
  2. CLK-789

SpringClickServlet injection fails if "Page" class name starts with two or more upper case letters

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.0
    • Fix Version/s: 2.4.0-RC1
    • Component/s: core
    • Labels:
    • Environment:
      Apache Tomcat 6.0.32 or 7.0.16. JRE 1.6.0_29 on Linux.
      Spring Framework 3.0.5.

      Description

      I am using SpringClickServlet to integrate Click with Spring.

      Spring injection in "Page" classes works only if the class name starts with exactly one upper case letter.

      If I have a class "ABTestPage" (that extends org.apache.click.Page and that is a @Component) when I try to use it, any @Resource is "null". If I rename the class to "AbTestPage", any @Resource is correctly injected.

      The following simple project demonstrates the problem: https://bitbucket.org/andcoz/clickspringuppercasebug/

        Activity

        Andrea Cozzolino created issue -
        Hide
        Naoki Takezoe added a comment -

        Spring's AnnotationBeanNameGenerator generates the bean name for components which registered by annotation using Introspector#decapitalize().
        So SpringClickServlet#toBeanName() should use it instead of the current implementation.

        Index: extras/src/org/apache/click/extras/spring/SpringClickServlet.java
        ===================================================================
        — extras/src/org/apache/click/extras/spring/SpringClickServlet.java (revision 1308655)
        +++ extras/src/org/apache/click/extras/spring/SpringClickServlet.java (working copy)
        @@ -18,6 +18,7 @@
        */
        package org.apache.click.extras.spring;

        +import java.beans.Introspector;
        import java.lang.reflect.Method;
        import java.util.ArrayList;
        import java.util.HashMap;
        @@ -518,9 +519,7 @@

        • @return the class bean name
          */
          protected String toBeanName(Class<?> aClass) { - String className = aClass.getName(); - String beanName = className.substring(className.lastIndexOf(".") + 1); - return Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1); + return Introspector.decapitalize(aClass.getSimpleName()); }

        // Package Private Inner Classes ------------------------------------------

        Show
        Naoki Takezoe added a comment - Spring's AnnotationBeanNameGenerator generates the bean name for components which registered by annotation using Introspector#decapitalize(). So SpringClickServlet#toBeanName() should use it instead of the current implementation. Index: extras/src/org/apache/click/extras/spring/SpringClickServlet.java =================================================================== — extras/src/org/apache/click/extras/spring/SpringClickServlet.java (revision 1308655) +++ extras/src/org/apache/click/extras/spring/SpringClickServlet.java (working copy) @@ -18,6 +18,7 @@ */ package org.apache.click.extras.spring; +import java.beans.Introspector; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; @@ -518,9 +519,7 @@ @return the class bean name */ protected String toBeanName(Class<?> aClass) { - String className = aClass.getName(); - String beanName = className.substring(className.lastIndexOf(".") + 1); - return Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1); + return Introspector.decapitalize(aClass.getSimpleName()); } // Package Private Inner Classes ------------------------------------------
        Naoki Takezoe made changes -
        Field Original Value New Value
        Assignee Naoki Takezoe [ takezoe ]
        Naoki Takezoe made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Naoki Takezoe made changes -
        Fix Version/s 2.3.1 [ 12316327 ]
        Naoki Takezoe committed 1327792 (1 file)
        Reviews: none

        [CLK-789]SpringClickServlet#toBeanName() use Introspector#decapitalize() to generate the Spring bean name from the page class name.

        Hide
        Naoki Takezoe added a comment -

        Fixed in the trunk.

        Show
        Naoki Takezoe added a comment - Fixed in the trunk.
        Naoki Takezoe made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Naoki Takezoe
            Reporter:
            Andrea Cozzolino
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development