Package com.interface21.web.servlet.mvc.multiaction

Package allowing MVC Controller implementations to handle requests at method rather than class level.


Interface Summary
MethodNameResolver Interface that parameterizes the MultiActionController class using the Strategy GoF Design pattern, allowing the mapping from incoming request to handler method name to be varied without affecting other application code.

Class Summary
InternalPathMethodNameResolver Simple implementation of MethodNameResolver that maps URL to method name.
MultiActionController Controller implementation that allows multiple request types to be handled by the same class.
Subclasses of this class can handle several different types of request with methods of the form ModelAndView actionName(HttpServletRequest request, HttpServletResponse response); May take a third parameter HttpSession in which an existing session will be required, or a third parameter of an arbitrary class that gets treated as command (i.e. an instance of the class gets created, and request parameters get bound to it)
These methods can throw any kind of exception, but should only let propagate those that they consider fatal, or which their class or superclass is prepared to catch by implementing an exception handler.
ParameterMethodNameResolver Simple implementation of MethodNameResolver that looks for a parameter value containing the name of the method to invoke.
PropertiesMethodNameResolver The most sophisticated and useful framework implementation of the MethodNameResolver interface.

Exception Summary
NoSuchRequestHandlingMethodException Exception thrown when there's no request handling method for this request.

Package com.interface21.web.servlet.mvc.multiaction Description

Package allowing MVC Controller implementations to handle requests at method rather than class level. This is useful when we want to avoid having many trivial controller classes, as can easily happen when using an MVC framework.

Typically a controller that handles multiple request types will extend MultiActionController, and implement multiple request handling methods that will be invoked by reflection if they follow this class' naming convention. Classes are analyzed at startup and methods cached, so the performance overhead of reflection in this approach is negligible.

This approach is analogous to the Struts 1.1 DispatcherAction class, but more sophisticated, as it supports configurable mapping from requests to URLs and allows for delegation as well as subclassing.

This package is discussed in Chapter 12 of Expert One-On-One J2EE Design and Development by Rod Johnson, and used in the sample application.

Rod Johnson and Spring contributors 2001-2003.