Click
  1. Click
  2. CLK-375

spring bean name generator for click pages

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.5 M1
    • Fix Version/s: None
    • Component/s: extras
    • Labels:
      None
    • Environment:
      java 1.4, spring framework 2.5

      Description

      Currently, SpringClickServlet is incompatible with @Component annotation of spring framework. For example, it is not possible to write:

      package com.example;

      // ...

      public @Component
      class HomePage extends Page

      { @Autowired private ExampleService exampleService; }

      The reason is SpringClickServlet is looking for bean 'com.example.HomePage', where as spring generates bean name 'homePage'. The solution is to write new bean name generator for click pages. Here is how to use it:

      <context:component-scan
      name-generator="net.sf.click.extras.spring.PageBeanNameGenerator"
      base-package="com.clickweb.quickstart" />
      <context:annotation-config />

      The code for PageBeanNameGenerator.java (jdk1.4, spring framework 2.5):

      package net.sf.click.extras.spring;

      import net.sf.click.Page;

      import org.springframework.beans.factory.config.BeanDefinition;
      import org.springframework.beans.factory.support.BeanDefinitionRegistry;
      import org.springframework.beans.factory.support.BeanNameGenerator;
      import org.springframework.context.annotation.AnnotationBeanNameGenerator;
      import org.springframework.util.ClassUtils;

      public class PageBeanNameGenerator extends AnnotationBeanNameGenerator
      implements BeanNameGenerator {

      public String generateBeanName(BeanDefinition definition,
      BeanDefinitionRegistry registry) {
      try {
      final Class clazz = ClassUtils.forName(definition
      .getBeanClassName());
      if (ClassUtils.isAssignable(Page.class, clazz))

      { return definition.getBeanClassName(); }

      } catch (Exception e)

      { // do nothing... use default bean name generator }

      return super.generateBeanName(definition, registry);
      }

      }

        Activity

          People

          • Assignee:
            Malcolm Edgar
            Reporter:
            Alexei Sokolov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development