spring webflow control standard MVC @Conroller pages

213 Views Asked by At

Is it possible to apply spring webflow flow to existing MVC pages (backed by @Controller, not pure jsp)?

eg I have @RequestMapping(/start) @RequestMapping(/buy) @RequestMapping(/confirm) @RequestMapping(/pay) and I would like to put them in flow /buy->/cofirm->/pay without possibility of custom navigation - can I do it with webflow ?

AFAIK it is not possible, but I want to make sure.

1

There are 1 best solutions below

0
On

Spring webflow and mvc work together - in fact webflow is built on top of mvc.

The mechanics of setting it up are a different thing. I am still learning about this, but here is what I believe happens based on tracking the logs:

At startup, the spring core processes all of hte annotations and spring configuration files. Among other things It assigns URL mappings for the webflow registry and classes annotated with @Controller.

The bean org.springframework.webflow.mvc.servlet.FlowHandlerMapping handles the mappings for webflow url's. You must ensure that this is interpreted before the mapping registered by other means (xml or @Controller beans).

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="order" value="-1" />
</bean>

At runtime, the URL is passed from the servlet engine into the mvc mapping resolver. This part of the mvc engine scans all of the registered resources, and returns the first one it finds that matches.

Given a flowregistry bean defined:

<webflow:flow-registry id="flowRegistry"
    flow-builder-services="flowBuilderServices"
    base-path="/WEB-INF/pages/">
    <webflow:flow-location path="login.xml" />
</webflow:flow-registry>

A controller bean defined:

@Controller
@RequestMapping("/login")
public class LoginController {
...
}

Mappings found in the webflow will take precedence over those found in the controller (provided everything else is configured correctly).

I have found that the conventions for setting up webflow projects are not particularly well documented. To get a working webflow project, I ended up extracting configurations from about 6 "ready to run" tutorial demos. Everything made sense once I got things running.

The only symptom of configuration problems is that mappings aren't found, so you will depend heavily on debug logging of org.springframework.web and org.springframework.webflow to figure out why mappings aren't found. I ended up debugging into the spring code before I "got" it, and I am still struggling with some concepts.

I hope this helps.