Monday, 10 January 2011

Spring 2.x MVC Controller Classes - What do they do?

The Spring framework provides a whole class hierarchy of MVC controllers, but the big question is, where and when do you use each one?
Broadly speaking, there are two main types of controller: normal controllers and form controllers. A normal controller links to it’s next page using an <a> link or http GET, whilst a form controller page contains an HTML form (plus a button) and uses a HTTP POST. So the first decision is simple: is you page a form or a normal page?

ParameterizableViewControllerA controller that uses a parameter to return a static view (one without data from the DB)
MultiActionControllerA controller that can delegate to 0 or more (1 or more) 'delegate' objects in order to determine the next view. (Strategy Pattern)
AbstractFormControllerA basic form controller that automatically populates the form bean with incoming data
SimpleFormControllerA form controller that handles a form that uses one screen.
AbstractWizardFormControllerA form controller that chains multiple forms together.

March 2011 -> don't forget that these MVC classes have now been deprecated in Spring 3.x.