Choosing a Controller for your work in Spring MVC

July 24, 2008

Spring provides good number of well structured Controller to work with Spring MVC and work flow. If you are familiar with Spring frame work, you must have work with two master piece controller SimpleFormControllerand and AbstractController. One for only view read-only request and other one includes full form handling mechanism. But this are not the end of the world. There are several Controllers that one can choose for various purpose.

AbstractWizardFormController Think about a form thats large in length. User have to scroll down dipper to fill up all the necessary fields of a form. Suppose, you are filling a long form to be a member of a job site, where there are sections like Name and Address, Job experience, Educational back grounds, Achievements e.t.c. But if all those thing bind with a single been then how about Splits this form across multiple pages? If you really want to do some thing like this, this is the controller for you :D

MultiActionController You are working with Spring MVC not in Web-Flow. But some time it needs to handle more work flow than a single one. Well though its possible to do the same task with AbstractFormController but the number of Controller will be more. For handling multiple action, this controller provides three different method:
public ModelAndView doStuff(HttpServletRequest req,
HttpServletResponse res) { … }
public ModelAndView doOtherStuff(HttpServletRequest req,
HttpServletResponse res, HttpSession session) { … }
public ModelAndView doStuff(HttpServletRequest req,
HttpServletResponse res, CommandBean command) { … }

One can choose any one of those on his requirement. But the basic problem with this Controller is it does not provide any work flow. All of this must be done by manually.

ThrowawayController The flavour of Command Pattern comes with this controller in Spring MVC. If you do not like to work with request/response stateless controller. The controller itself work as a command bean. Non-singleton. Lack of validation enforce another version of the controller named ValidatableThrowawayController.

By: Md. Shahjalal


Follow

Get every new post delivered to your Inbox.