com.interface21.web.servlet.mvc
Class AbstractController

java.lang.Object
  |
  +--com.interface21.context.support.ApplicationObjectSupport
        |
        +--com.interface21.web.servlet.mvc.WebContentGenerator
              |
              +--com.interface21.web.servlet.mvc.AbstractController
All Implemented Interfaces:
ApplicationContextAware, Controller
Direct Known Subclasses:
BaseCommandController, ParameterizableViewController

public abstract class AbstractController
extends WebContentGenerator
implements Controller

Convenient superclass for controller implementations, using the Template Method design pattern.

Exposes the following bean properties:

Author:
Rod Johnson

Fields inherited from class com.interface21.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
AbstractController()
          Create a new Controller supporting GET and POST methods.
 
Method Summary
 ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process the request and return a ModelAndView object which the DispatcherServlet will render.
protected abstract  ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Template method.
 void setCacheSeconds(int seconds)
          If 0 disable caching, default is no caching header generation.
 void setRequireSession(boolean requireSession)
          Is a session required to handle requests?
 void setSupportedMethods(java.lang.String[] supportedMethodsArray)
          Set supported methods as CSV.
 
Methods inherited from class com.interface21.web.servlet.mvc.WebContentGenerator
cacheForSeconds, preventCaching, setUseExpiresHeader
 
Methods inherited from class com.interface21.context.support.ApplicationObjectSupport
getApplicationContext, initApplicationContext, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractController

public AbstractController()
Create a new Controller supporting GET and POST methods.
Method Detail

setSupportedMethods

public final void setSupportedMethods(java.lang.String[] supportedMethodsArray)
                               throws ApplicationContextException
Set supported methods as CSV. The String[] property editor will get the type right.

setRequireSession

public final void setRequireSession(boolean requireSession)
Is a session required to handle requests?

setCacheSeconds

public final void setCacheSeconds(int seconds)
If 0 disable caching, default is no caching header generation. Only if this is set to 0 (no cache) or a positive value (cache for this many seconds) will this class generate cache headers. They can be overwritten by subclasses anyway, before content is generated.

handleRequest

public final ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)
                                 throws javax.servlet.ServletException,
                                        java.io.IOException
Description copied from interface: Controller
Process the request and return a ModelAndView object which the DispatcherServlet will render. A null return is not an error. It indicates that this object completed request processing itself, thus there is no ModelAndView to render.
Specified by:
handleRequest in interface Controller
Following copied from interface: com.interface21.web.servlet.mvc.Controller
Parameters:
request - current HTTP request
response - current HTTP response
Returns:
a ModelAndView to render, or null if handled directly

handleRequestInternal

protected abstract ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response)
                                               throws javax.servlet.ServletException,
                                                      java.io.IOException
Template method. Subclasses must implement this. The contract is the same as for handleRequest.
See Also:
handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)


Rod Johnson and Spring contributors 2001-2003.