Content Application Developer Manual / Version 2404
Table Of ContentsSpring Web Flow is a framework for building complex form based web applications. Since it is based on Spring MVC, it can be easily integrated into any existing CAE web application.
CoreMedia provides an integration for merging Web Flows into a content based CAE application: a typical page that is delivered by a CAE application is composed of several hierarchical structured content beans, each of them representing a certain fragment of the page. Typically, a (Web Flow) form application should be embedded in a page as a fragment only.
In other words: Spring Web Flow result beans need to be merged into the CAE bean model.
Embedding Web Flows
First of all, creating web flows for the CAE does not differ from creating "standard" web flows: writing flow definitions, form beans etc. is exactly the same in the CAE.
The main difference lies in the way the flow execution is controlled: The standard org.springframework.webflow.mvc.servlet.FlowController takes over the control of the request including the rendering of the model. It uses an org.springframework.webflow.context.servlet.FlowUrlHandler for building and parsing adequate URLs pointing to this controller.
The CAE integration works in a slightly different way: the request can be still controlled by a
custom controller which builds its ModelAndView
traditionally. After that,
it temporarily delegates the request to the Web Flow engine (by invoking
FlowRunner#run).
This runner executes the Web Flow logic and returns an enriched model consisting of the original
model merged with the Web Flow model, a form and binding results, for instance. This merged
model can be passed to the view rendering process (for instance the templates) that render the
entire page containing the fragment with the flow results.
Example
A typical handler/controller method may look like this:
// step#1: build content model ModelAndView modelAndView = ...; // step#2: fetch flow id similar to // FlowUrlHandler#getFlowId(HttpServletRequest) String flowId = ...; // step#3: run flow and enrich model ModelAndView mergedModelAndView = flowRunner.run( flowId, modelAndView, request, response); // step#4: pass merged model to rendering engine. // Note, that it might be null in case that webflow has handled // the response directly, e.g. by sending a 302 redirect return mergedModelAndView;
Configuration
In order to use the Web Flow integration, the artifact dependency coremedia-webflow
as well as a Spring bean configuration <import
resource="classpath:/com/coremedia/cae/webflow/webflow-services.xml"/>
must be added
to the application. The latter contains CAE specific web flow infrastructure setup as well as the
bean flowRunner
. This bean can be used by custom handler in the way described
above.
Finally, custom flow definitions still need to be registered:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"> <webflow:flow-location-pattern value="classpath:/com/mycompany/**/*-flow.xml" /> </webflow:flow-registry>