Spring Webflow + Spring MVC: Action Bean in Java Annotation

I'm using Spring MVC + Spring Webflow 2.

I would like to define a @Bean for an action-state, but i don't know how to do this in Java Annotation, as i get this error:

Method call: Method execute() cannot be found on com.myapp.action.GaraAgenziaAction type

here an example of what i want to do: spring-webflow-no-actions-were-executed

My Bean:

import org.springframework.webflow.execution.Action;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

public class GaraAgenziaAction implements Action {

    @Override
    public Event execute(RequestContext rc) throws Exception {                
        return new Event(this, "success");
    }
}

Flow XML:

<transition on="fail" to="gara-agenzie"/>

<transition on="success" to="gara-conferma"/>

My webAppConfig:

@Bean
public Action GaraAgenziaAction()
{
    GaraAgenziaAction garaAgenziaAction = new GaraAgenziaAction();

    return garaAgenziaAction;

}

Thank you very much



UPDATE resolved thanks to @Prasad suggestions:

My Bean (added @Component):

import org.springframework.stereotype.Component;
import org.springframework.webflow.execution.Action;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

@Component
public class GaraAgenziaAction implements Action {

    @Override
    public Event execute(RequestContext rc) throws Exception {                
        return new Event(this, "success");
    }
}

My webAppConfig (changed name of the bean with lowercase):

@Bean
public Action garaAgenziaAction()
{
    GaraAgenziaAction beanAction = new GaraAgenziaAction();

    return beanAction;

}

Flow XMl configuration (changed bean name to lowercase and pass flowRequestContext as parameter):

<action-state id="action-agenzie">
    <evaluate expression="garaAgenziaAction.execute(flowRequestContext)"></evaluate>        

    <transition on="fail" to="gara-agenzie"/>

    <transition on="success" to="gara-conferma"/>
</action-state>

Now it's working fine!


Define the action class in your servlet xml file as:

    <!--Class which handles the flow related actions-->
    <bean id="garaAgenziaAction" class=" com.myapp.action.GaraAgenziaAction">
    </bean>

or annotate it with Component as:

    @Component
    public class GaraAgenziaAction implements Action{
            @Override
            public Event execute(RequestContext rc) throws Exception {                
            return new Event(this, "success");
            }
    }

In your flow xml access it as:

    <action-state id="action-agenzie">
        <evaluate expression="garaAgenziaAction.execute(flowRequestContext)"></evaluate>
        <transition on="fail" to="gara-agenzie"/>
        <transition on="success" to="gara-conferma"/>
    </action-state>

For configuration details you can find it in the answer in this link.

链接地址: http://www.djcxy.com/p/39160.html

上一篇: Spring Web流式表单绑定附加到列表中

下一篇: Spring Webflow + Spring MVC:Java注释中的Action Bean