How to pass parameters to spring webflow?

Tom picture Tom · Sep 21, 2010 · Viewed 15.3k times · Source

First of all, 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

Answer

digz6666 picture digz6666 · Jan 14, 2011

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;
    }
}