开发者

How to pass parameters to spring webflow?

First of all开发者_如何学Go, I don't know how can config restful url request for spring webflow, for example,how can I invoke my webflow when type address: http://localhost/app/order/edit/1002

It's easy to write spring mvc controller to handle this,but in case of webflow, I don't know how to pass parameters.

Can anybody help me? Thanks


Try reading request parameter like following. It processes "http://example.com/message?messageId=3" but when rendering view, the URL changes to something like "http://example.com/message?execution=e1s1".

Flow code:

<?xml version="1.0" encoding="UTF-8"?>
    <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">

    <on-start>
        <evaluate expression="FooWebFlowController.create(flowRequestContext)"
                  result="flowScope.fooModel"/>
    </on-start>

    <view-state id="view" model="fooModel" view="fooView">
    </view-state>
</flow>

FooWebFlowController bean:

import org.springframework.webflow.execution.RequestContext;

@Component
public class FooWebFlowController {

    @Autowired
    private FooDAO fooDAO;

    public Foo create(RequestContext requestContext) {
        String messageId = requestContext.getRequestParameters().get("messageId")
        Foo foo = fooDAO.findByMessagId(messageId);
        return foo;
    }
}


Is the RequestPathFlowExecutorArgumentHandler what you're looking for?

Flow executor argument handler that extracts arguments from the request path and exposes them in the URL path.

This allows for REST-style URLs to launch flows in the general format: http://${host}/${context path}/${dispatcher path}/${flowId}

<bean id="flowController" class="org.springframework.webflow.executor.mvc.FlowController">
    <property name="flowExecutor" ref="flowExecutor" />
    <property name="argumentHandler">
        <bean class="org.springframework.webflow.executor.support.RequestPathFlowExecutorArgumentHandler" />
    </property>
</bean>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜