beehive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niels Harremoes <>
Subject Re: Integrating netui with spring using FlowControllerFactory
Date Tue, 13 Feb 2007 17:57:03 GMT

OK, here's my first shot at an implementation. 
It doesn't handle serialization of FlowControllers during session
replication. And I haven't tested how it would work if the controller end up
getting wrapped/proxied by spring. It wires up controllers based on their
class name - this could possibly be improved?

// start 
import org.apache.beehive.netui.pageflow.FlowController;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;

import javax.servlet.ServletContext;

 * Override standard FlowControllerFactroy to spring inject properties in
new controllers
public class SpringPageflowControllerFactory extends
org.apache.beehive.netui.pageflow.FlowControllerFactory {

  ApplicationContext applicationContext;

 /** Grab the spring web context - use
org.springframework.web.context.ContextLoaderListener to set this up */
  protected void reinit(ServletContext servletContext) {
    applicationContext =

   * Allow Spring to configure the controller instantiated by the super
   * @param controllerClass The desired class of the controller
   * @return A new controller which has been cofnigured by spring 
   * @throws InstantiationException if thrown by super implementation
   * @throws IllegalAccessException if thrown by super implementation
  public FlowController getFlowControllerInstance(Class controllerClass) 
                                   throws InstantiationException,
IllegalAccessException {
    FlowController flowController =

    // Now, spring inject properties based on the class
    String beanName = controllerClass.getName();
    if (applicationContext.containsBeanDefinition(beanName)) {
      log.debug("Wiring up controller " + beanName);
      AutowireCapableBeanFactory autowireCapableBeanFactory =
      flowController = (FlowController)
autowireCapableBeanFactory.configureBean(flowController, beanName);
    } else {
      log.debug("No bean definition found for bean " + beanName);

    return flowController;

// end 

In myflow/, I then add

  String testProperty = "It doesn't work";

  // Injected through spring
  public void setTestProperty(String testProperty) {
    this.testProperty = testProperty;

And in my springWebContext.xml:

  <bean name="myflow.Controller" class="myflow.Controller" abstract="true">
    <property name="testProperty" value="It works"/>

View this message in context:
Sent from the Beehive - User mailing list archive at

View raw message