Results 1 to 2 of 2

Thread: Invoking Custom Actions from an <action-state>

  1. #1
    Join Date
    Feb 2007
    Location
    Ann Arbor, Michigan
    Posts
    48

    Default Invoking Custom Actions from an <action-state>

    I'm missing something about the use of <action-state> with custom actions. Here's my super simple custom action:

    Code:
    public class HelloWorldLoggingAction implements Action {
    
    	private Logger log = LoggerFactory.getLogger(HelloWorldLoggingAction.class);
    
    	public Event execute(RequestContext context) throws Exception {
    		log.info("Hello World!");
    		return new Event(this, "end");
    	}
    }
    I then define that bean in my application context file.

    And my super simple flow definition:
    Code:
    <flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    
        <action-state id="HelloWorldLogging">
            <evaluate expression="helloWorldLogging" />
            <transition on="end" to="end" />
        </action-state>
        
        <end-state id="end" />
    </flow>
    However, the error I get is:
    org.springframework.expression.spel.SpelEvaluation Exception: EL1008Epos 0): Field or property 'helloWorldLogging' cannot be found on object of type 'org.springframework.webflow.engine.impl.RequestCo ntrolContextImpl'
    Now, the error message itself seems perfectly reasonable. I wouldn't have expected the "helloWorldLogging" logging bean to be in the RequestControlContext but in the application context. So, I'm clearly not connecting some dots here. Can some one point me in the right direction?
    Chad

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    Not entirely sure if you've got the right idea here. An action-state doesn't directly map to an object, as you seem to think it does.

    The important part isn't the action-state at all, but within that expression within your evaluate element. The way you have it right now, you're giving it "helloWorldLogging", so it will try to look up either an implicit object of that name (no match), then it will search in its various scopes (request, flash, view, flow, conversation) for an attribute of that name. You haven't placed your object into any scope, so it won't find it. Thus the exception.

    To make this work, HelloWorldLoggingAction (which shouldn't implement Action, by the way, it can be a POJO) needs to be registered in some kind of scope, either in your beans-config file or through annotation. It also needs to be in a scope accessible to SWF (the scopes mentioned above, though there is a more complex way needed to get a hold of session-scoped objects). So if you're using annotation-based configuration, you can add a "@Component" to your class and it should pick it up, addressing it as a singleton.

    Once that's done, you can execute your method from the evaluate element with the expression "helloWorldLogging.execute(flowRequestContext) ", though since you're using a POJO you aren't restricted to that method signature or just that parameter.
    Last edited by InverseFalcon; Jul 12th, 2012 at 09:04 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •