uk.co.lakesidetech.spxforms.web.servlet.mvc
Class BaseSpXCommandController

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.support.WebContentGenerator
              extended byorg.springframework.web.servlet.mvc.AbstractController
                  extended byuk.co.lakesidetech.spxforms.web.servlet.mvc.BaseSpXCommandController
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware, org.springframework.web.servlet.mvc.Controller
Direct Known Subclasses:
AbstractSpXFormsController

public abstract class BaseSpXCommandController
extends org.springframework.web.servlet.mvc.AbstractController

Author:
Stuart Eccles

Field Summary
static java.lang.String DEFAULT_COMMAND_NAME
           
 
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator
HEADER_CACHE_CONTROL, HEADER_EXPIRES, HEADER_PRAGMA, METHOD_GET, METHOD_POST
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
BaseSpXCommandController()
           
 
Method Summary
protected  ServletRequestSpXFormsDataBinder bindAndValidate(javax.servlet.http.HttpServletRequest request, java.lang.Object command)
          Bind the parameters of the given request to the given command object.
protected  ServletRequestSpXFormsDataBinder createBinder(javax.servlet.http.HttpServletRequest request, java.lang.Object command)
          Create a new binder instance for the given command and request.
protected  java.lang.Object createCommand()
          Create a new command instance for the command class of this controller.
protected  java.lang.Object getCommand(javax.servlet.http.HttpServletRequest request)
          Retrieve a command object for the given request.
protected  java.lang.Class getCommandClass()
          Return the command class for this controller.
protected  java.lang.String getCommandName()
          Return the name of the command in the model.
protected  org.springframework.validation.MessageCodesResolver getMessageCodesResolver()
          Return the strategy to use for resolving errors into message codes.
protected  org.springframework.validation.Validator getValidator()
          Return the primary Validator for this controller.
protected  org.springframework.validation.Validator[] getValidators()
          Return the Validators for this controller.
protected  void initApplicationContext()
           
protected  void initBinder(javax.servlet.http.HttpServletRequest request, ServletRequestSpXFormsDataBinder binder)
          Initialize the given binder instance, for example with custom editors.
protected  boolean isValidateOnBinding()
          Return if the Validator should get applied when binding.
protected  void onBind(javax.servlet.http.HttpServletRequest request, java.lang.Object command)
          Callback for custom post-processing in terms of binding.
protected  void onBind(javax.servlet.http.HttpServletRequest request, java.lang.Object command, org.springframework.validation.BindException errors)
          Callback for custom post-processing in terms of binding.
protected  void onBindAndValidate(javax.servlet.http.HttpServletRequest request, java.lang.Object command, org.springframework.validation.BindException errors)
          Callback for custom post-processing in terms of binding and validation.
 void setCommandClass(java.lang.Class commandClass)
          Set the command class for this controller.
 void setCommandName(java.lang.String commandName)
          Set the name of the command in the model.
 void setMessageCodesResolver(org.springframework.validation.MessageCodesResolver messageCodesResolver)
          Set the strategy to use for resolving errors into message codes.
 void setValidateOnBinding(boolean validateOnBinding)
          Set if the Validator should get applied when binding.
 void setValidator(org.springframework.validation.Validator validator)
          Set the Validators for this controller.
 void setValidators(org.springframework.validation.Validator[] validators)
          Set the primary Validator for this controller.
protected  boolean suppressValidation(javax.servlet.http.HttpServletRequest request)
          Return whether to suppress validation for the given request.
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController
handleRequest, handleRequestInternal, isSynchronizeOnSession, setSynchronizeOnSession
 
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMMAND_NAME

public static final java.lang.String DEFAULT_COMMAND_NAME
See Also:
Constant Field Values
Constructor Detail

BaseSpXCommandController

public BaseSpXCommandController()
Method Detail

setCommandName

public final void setCommandName(java.lang.String commandName)
Set the name of the command in the model. The command object will be included in the model under this name.


getCommandName

protected final java.lang.String getCommandName()
Return the name of the command in the model.


setCommandClass

public final void setCommandClass(java.lang.Class commandClass)
Set the command class for this controller. An instance of this class gets populated and validated on each request.


getCommandClass

protected final java.lang.Class getCommandClass()
Return the command class for this controller.


setValidators

public final void setValidators(org.springframework.validation.Validator[] validators)
Set the primary Validator for this controller. The Validator must support the specified command class.


getValidators

protected final org.springframework.validation.Validator[] getValidators()
Return the Validators for this controller.


setValidator

public final void setValidator(org.springframework.validation.Validator validator)
Set the Validators for this controller. The Validator must support the specified command class.


getValidator

protected final org.springframework.validation.Validator getValidator()
Return the primary Validator for this controller.


setValidateOnBinding

public final void setValidateOnBinding(boolean validateOnBinding)
Set if the Validator should get applied when binding.


isValidateOnBinding

protected final boolean isValidateOnBinding()
Return if the Validator should get applied when binding.


setMessageCodesResolver

public final void setMessageCodesResolver(org.springframework.validation.MessageCodesResolver messageCodesResolver)
Set the strategy to use for resolving errors into message codes. Applies the given strategy to all data binders used by this controller.

Default is null, i.e. using the default strategy of the data binder.

See Also:
createBinder(javax.servlet.http.HttpServletRequest, java.lang.Object), DataBinder.setMessageCodesResolver(org.springframework.validation.MessageCodesResolver)

getMessageCodesResolver

protected final org.springframework.validation.MessageCodesResolver getMessageCodesResolver()
Return the strategy to use for resolving errors into message codes.


initApplicationContext

protected void initApplicationContext()

getCommand

protected java.lang.Object getCommand(javax.servlet.http.HttpServletRequest request)
                               throws java.lang.Exception
Retrieve a command object for the given request.

Default implementation calls createCommand. Subclasses can override this.

Parameters:
request - current HTTP request
Returns:
object command to bind onto
Throws:
java.lang.Exception
See Also:
createCommand()

createCommand

protected java.lang.Object createCommand()
                                  throws java.lang.InstantiationException,
                                         java.lang.IllegalAccessException
Create a new command instance for the command class of this controller.

Returns:
the new command instance
Throws:
java.lang.InstantiationException - if the command class could not be instantiated
java.lang.IllegalAccessException - if the class or its constructor is not accessible

bindAndValidate

protected final ServletRequestSpXFormsDataBinder bindAndValidate(javax.servlet.http.HttpServletRequest request,
                                                                 java.lang.Object command)
                                                          throws java.lang.Exception
Bind the parameters of the given request to the given command object.

Parameters:
request - current HTTP request
command - the command to bind onto
Returns:
the ServletRequestDataBinder instance for additional custom validation
Throws:
java.lang.Exception - in case of invalid state or arguments

createBinder

protected ServletRequestSpXFormsDataBinder createBinder(javax.servlet.http.HttpServletRequest request,
                                                        java.lang.Object command)
                                                 throws java.lang.Exception
Create a new binder instance for the given command and request. Called by bindAndValidate. Can be overridden to plug in custom ServletRequestDataBinder subclasses.

Default implementation creates a standard ServletRequestDataBinder, sets the specified MessageCodesResolver (if any), and invokes initBinder. Note that initBinder will not be invoked if you override this method!

Parameters:
request - current HTTP request
command - the command to bind onto
Returns:
the new binder instance
Throws:
java.lang.Exception - in case of invalid state or arguments
See Also:
bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object), initBinder(javax.servlet.http.HttpServletRequest, uk.co.lakesidetech.spxforms.web.bind.ServletRequestSpXFormsDataBinder), setMessageCodesResolver(org.springframework.validation.MessageCodesResolver)

initBinder

protected void initBinder(javax.servlet.http.HttpServletRequest request,
                          ServletRequestSpXFormsDataBinder binder)
                   throws java.lang.Exception
Initialize the given binder instance, for example with custom editors. Called by createBinder.

This method allows you to register custom editors for certain fields of your command class. For instance, you will be able to transform Date objects into a String pattern and back, in order to allow your JavaBeans to have Date properties and still be able to set and display them in an HTML interface.

Default implementation is empty.

Parameters:
request - current HTTP request
binder - new binder instance
Throws:
java.lang.Exception - in case of invalid state or arguments
See Also:
createBinder(javax.servlet.http.HttpServletRequest, java.lang.Object), DataBinder.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor), org.springframework.beans.propertyeditors.CustomDateEditor

onBind

protected void onBind(javax.servlet.http.HttpServletRequest request,
                      java.lang.Object command,
                      org.springframework.validation.BindException errors)
               throws java.lang.Exception
Callback for custom post-processing in terms of binding. Called on each submit, after standard binding but before validation.

Default implementation delegates to onBind(request, command).

Parameters:
request - current HTTP request
command - the command object to perform further binding on
errors - validation errors holder, allowing for additional custom registration of binding errors
Throws:
java.lang.Exception - in case of invalid state or arguments
See Also:
bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object), onBind(HttpServletRequest, Object)

onBind

protected void onBind(javax.servlet.http.HttpServletRequest request,
                      java.lang.Object command)
               throws java.lang.Exception
Callback for custom post-processing in terms of binding. Called by the default implementation of the onBind version with all parameters, after standard binding but before validation.

Default implementation is empty.

Parameters:
request - current HTTP request
command - the command object to perform further binding on
Throws:
java.lang.Exception - in case of invalid state or arguments
See Also:
onBind(HttpServletRequest, Object, BindException)

suppressValidation

protected boolean suppressValidation(javax.servlet.http.HttpServletRequest request)
Return whether to suppress validation for the given request. Default implementations always returns false.

Parameters:
request - current HTTP request
Returns:
whether to suppress validation for the given request

onBindAndValidate

protected void onBindAndValidate(javax.servlet.http.HttpServletRequest request,
                                 java.lang.Object command,
                                 org.springframework.validation.BindException errors)
                          throws java.lang.Exception
Callback for custom post-processing in terms of binding and validation. Called on each submit, after standard binding and validation, but before error evaluation.

Default implementation is empty.

Parameters:
request - current HTTP request
command - the command object, still allowing for further binding
errors - validation errors holder, allowing for additional custom validation
Throws:
java.lang.Exception - in case of invalid state or arguments
See Also:
bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object), Errors