Expert Spring MVC and Web Flow

(Dana P.) #1
Listing 6-54.Person Controller Constructor with Redirect:Pprefix

public PersonFormController() {
setCommandName("person");
setCommandClass(Person.class);
setFormView("newPerson");
setSuccessView("redirect:/app/personSuccess");
}

Redirect After Submit Summary
The redirect after submitpattern, sometimes known as redirect after POST, is a method to pro-
tect the client from resubmitting a form. By sending a HTTP redirect, the client is sent to a
different page after the form is submitted, effectively leaving the original form’s page. Any
attempts to reload the page will simple reload the success page instead of the original form.

MultiActionController


SimpleFormControlleris great when you need to model a form work flow with one page view
and one form submission. There are, however, some situations where you might want one
Controllerto handle more than one work flow. For instance, you may have a logical group of
read-only operations, and subclassing an AbstractControllerfor each operation might be a
bit verbose for your application. The MultiActionControllerprovides a way to group multiple
actions, or request handlers, together in one controller.
The benefits of the MultiActionControllerinclude


  • fewer physical controllers, thus fewer classes in the system

  • logical grouping of actions in one class

  • flexible mapping for action methods.


The disadvantages of MultiActionControllerinclude


  • form handling work flow isn’t explicit, unlike SimpleFormController

  • possibility for large, confusing controllers handling many tasks

  • no compile-time checks can be performed due to the use of reflection.


So when does using MultiActionControllermake sense? We believe it is a perfect way to
consolidate actions that have a similar theme into one controller, when those actions do not
require a full form handling work flow. It’s also useful when the actual processing is performed
by a shared delegate. However, be wary of putting too many request handling methods inside
one MultiActionController, for it can quickly become too large and unwieldy.

■NoteThe MultiActionControlleris similar in nature to Struts’ DispatchAction,only much more
flexible.

168 CHAPTER 6 ■THE CONTROLLER MENAGERIE

Free download pdf