Dear Reader,
I am currently trying to integrate Spring Webflow on top of an application that has been written using Spring MVC approaches. That is especially this kind of controller methodology (from the Spring MVC part):
public ModelAndView showListOfferPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
//...
return new ModelAndView("path/tomy/viewJspFile", "dataKey", dataValue);
}
However, from what I’ve learned so far on Spring Webflow, all the View navigation decision is done in the Flow definition. This raises the question, how to intermix the different approaches. What confuses me is that in none of the examples seems to be any “context (request) aware” Class…
In every case, the controller layer needs the request object to extract data from it… So I would expect something like this:
public void showListOfferpage(HttpServletRequest request, HttpServletResponse response) throws Exception {
//... do stuff
// return nothing, as this is handled by the flow
}
I started a Thread on this topic on the Spring Framework Support Forums. So far it looks as if I had to answer this myself.
Let’s have a look into chapter 11 and 12 of the book “Expert Spring MVC and Web Flow” by Seth Ladd et al. This is an excellent book on the topic and very clearly written. The Webflow API from the book is a bit outdated. There have been some renamings, but with a look at the API of the latest release in combination with a bit of surfing the Spring Framework Support Forums, this should not be a problem.
Page 312:
“Impletation Agnostic – Secondly, Spring Web Flow is deliberately abstracted away from the Servlet specification. [...] there is nothing web-specific about a flow definition [...] At now point within Spring Web Flow are you presented with an HttpServletRequest or an HttpServletResponse.”
Well, that’s great but I need some way to plug the stuff together… I’ll find out… You will find an answer right here really soon.
Ok. Looks as if I missunderstood the “plug and play” property of Webflow…
Yes it is agnostic of the MVC framework it works with. Its tied to that using FlowController, ExternalContext and ViewResolver. But No, it doesn’t let you plug it on top of your already coded Spring MVC Controllers, like SimpleFormController or MultiActionController. The controller part is defined completely in the webflow definition. The MVC controllers are replaced with Spring Webflows Action’s.
This I conclude from a bit of reading in the previously mentioned book and on these two discussion threads:
1) from The Server Side
2) from the Spring Webflow Support Forum
Erwin Vervaet says in [2]: “So a typical application will mix both Spring MVC and SWF. Use simple controllers like SimpleFormController when that is all you need. When you have more complex flow requirements, use SWF.”
and Keith Donald in [1]: “On the other hand, if you already have a lot of flow type stuff implemented in Spring MVC, perhaps using the AbstractWizardController, well, yea, you have a conversion effort there if you want to web flow that existing code. But I think you should think carefully if that is worth doing: if what you have already built works, why change it? AWC works and will continue to; web flow will provide more power/flexibility where it is demanded.”
So I changed the bits and pieces I want to have as part of the Webflow framework like this:
from Spring MVC, using org.springframework.web.servlet.mvc.multiaction.MultiActionController
public class MyAction extends MultiActionController {
public ModelAndView getOffers(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
List offers = offerService.find(IOffer.class);
return new ModelAndView("pro/secured/offer/offerList", "offers", offers);
}
}
to Spring Webflow, using org.springframework.webflow.action.MultiAction
public class MyAction extends MultiAction {
public Event getOffers(final RequestContext context) throws Exception {
List offers = offerService.find(IOffer.class);
context.getFlowScope().put("offers", offers);
return success();
}
}
Thank you.