PDA

View Full Version : Variable page flow, best practices?


duckpuppy
Sep 11th, 2007, 02:40 PM
First off, I'm new to Spring and SpringMVC. I'm using 2.0.6 for this project.

I have a situation where I have three pages. My flow is as follows:
Page 1 - Very simple form (one element, a string). That string is used by a service in processFormSubmission to retrieve an object to be used as the model for page 3. An authorization check is then performed by another service - if the user is authorized to view that information, I need to go to the page 3 controller, with the object as the model (or at least available to be inserted into the model map). If the user is NOT authorized, go to page 2's controller. Both should be considered "success" views, as the error view is the same form with an "object not found, try again" style error message.

Page 2 (optional) - Display an audit form asking why the user needs the info. Log the reason in a database table using a logging service. Proceed to page 3 if the user chooses to continue past that point, return to page 1 if the user cancels.

Page 3 - use the object retrieved on page 1 to display detailed information.

I'm using JSPs for the views, with an InternalResourceViewResolver as the view resolver.

I can make each of those work independently - the problems I am having is how to redirect in the processFormSubmission of page 1 and, if necessary, page 2 so that the object from the first page is still available to be used as a model by page 3 AND each of the page's controllers are invoked, not just views.

This is the simple start of a much larger application. Also, I'm restricted with the requirement that there be NO client-side scripting - basic HTML markup only on the client, so doing the audit/reason step with client-side javascript is out.

I'd really appreciate any help here... the documentation, especially the examples, for SpringMVC is... sparse, especially for the 2.X releases.

Marten Deinum
Sep 11th, 2007, 04:32 PM
Take a look at the AbstractWizardFormController.

Examples spares, have you looked at the samples shipped with Spring? They all cover SpringMVC....

gmatthews
Sep 20th, 2007, 07:43 PM
Use Spring Webflow, not Spring MVC.

It makes it extremely easy to script navigation between pages, and pass context information around between pages.

We've dropped Spring MVC in favour of Webflow since it's 'manager proof', meaning that when the requirements change it becomes easy to script together a new use case which reuses existing pages/flows. Spring Webflow and Spring MVC can co-exist too.

With Spring MVC, if you want to control what page is displayed, then overriding getCurrentPage in AbstractWizardFormController is one part of the steps required.

If you're not using AbstractWizardFormController, and in fact using separate controllers, e.g. SimpleFormController, then you'll need to roll-you-own flow logic.