uk.co.lakesidetech.springframework.web.servlet.mvc.multiaction
Class SimpleMultiActionFormController

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 byorg.springframework.web.servlet.mvc.BaseCommandController
                      extended byorg.springframework.web.servlet.mvc.AbstractFormController
                          extended byorg.springframework.web.servlet.mvc.SimpleFormController
                              extended byuk.co.lakesidetech.springframework.web.servlet.mvc.multiaction.SimpleMultiActionFormController
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware, org.springframework.web.servlet.mvc.Controller

public abstract class SimpleMultiActionFormController
extends org.springframework.web.servlet.mvc.SimpleFormController

The SimpleMultiActionFormController provides a multiple form processing action similar to MultiActionController for form processing allowing a concrete class to benefit from the binding and error handling capabilties of the FormController but execute different submission actions.

As the SimpleFormController will execute binding and validation actions before processing the selected submit action, this may result in the action not executing if there are errors on the form even if this is not the final submit action.

When combined with the SubmitParameterPropertiesMethodNameResolver this form can handle different actions for different submit buttons much like the _finish and _cancel of the AbstractWizardFormController

Author:
Stuart Eccles, James Gellately-Smith

Field Summary
 
Fields inherited from class org.springframework.web.servlet.mvc.BaseCommandController
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
SimpleMultiActionFormController()
           
 
Method Summary
protected  void defaultBindAndValidate(javax.servlet.http.HttpServletRequest request, java.lang.Object command, org.springframework.validation.BindException errors)
          Subclasses can override this to provide cross action/method validation.
 org.springframework.web.servlet.mvc.multiaction.MethodNameResolver getMethodNameResolver()
          Get the method name resolver object
protected  void onBindAndValidate(javax.servlet.http.HttpServletRequest request, java.lang.Object command, org.springframework.validation.BindException errors)
           This method looks for validators/binders for the action by appending the word Validator onto the method name.
protected  org.springframework.web.servlet.ModelAndView processFormSubmission(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, org.springframework.validation.BindException errors)
           Process the form submission, if the form is errored then reshow the form otherwise resolve the method to call in the concrete class using the set MethodNameResolver
 void setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver methodNameResolver)
          Set the method name resolver objerct
 
Methods inherited from class org.springframework.web.servlet.mvc.SimpleFormController
doSubmitAction, getFormView, getSuccessView, isFormChangeRequest, onSubmit, onSubmit, onSubmit, referenceData, referenceData, setFormView, setSuccessView, showForm, suppressValidation
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractFormController
formBackingObject, getCommand, getErrorsForNewForm, getFormSessionAttributeName, handleInvalidSubmit, handleRequestInternal, isBindOnNewForm, isFormSubmission, isSessionForm, setBindOnNewForm, setSessionForm, showForm, showForm, showNewForm
 
Methods inherited from class org.springframework.web.servlet.mvc.BaseCommandController
bindAndValidate, checkCommand, createBinder, createCommand, getCommandClass, getCommandName, getMessageCodesResolver, getValidator, getValidators, initApplicationContext, initBinder, isValidateOnBinding, onBind, onBind, setCommandClass, setCommandName, setMessageCodesResolver, setValidateOnBinding, setValidator, setValidators
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController
handleRequest, 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
 

Constructor Detail

SimpleMultiActionFormController

public SimpleMultiActionFormController()
Method Detail

setMethodNameResolver

public final void setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver methodNameResolver)
Set the method name resolver objerct

Parameters:
methodNameResolver -

getMethodNameResolver

public final org.springframework.web.servlet.mvc.multiaction.MethodNameResolver getMethodNameResolver()
Get the method name resolver object

Returns:
the MethodNameResolver

onBindAndValidate

protected final void onBindAndValidate(javax.servlet.http.HttpServletRequest request,
                                       java.lang.Object command,
                                       org.springframework.validation.BindException errors)
                                throws java.lang.Exception

This method looks for validators/binders for the action by appending the word Validator onto the method name.

e.g. If the properties file defined a method foo for submit button this routine will look for the method:

       public void fooValidator(HttpServletRequest request,
                Object command, BindException errors);
 

Throws:
java.lang.Exception

defaultBindAndValidate

protected void defaultBindAndValidate(javax.servlet.http.HttpServletRequest request,
                                      java.lang.Object command,
                                      org.springframework.validation.BindException errors)
Subclasses can override this to provide cross action/method validation.

Parameters:
request -
command -
errors -

processFormSubmission

protected org.springframework.web.servlet.ModelAndView processFormSubmission(javax.servlet.http.HttpServletRequest request,
                                                                             javax.servlet.http.HttpServletResponse response,
                                                                             java.lang.Object command,
                                                                             org.springframework.validation.BindException errors)
                                                                      throws java.lang.Exception

Process the form submission, if the form is errored then reshow the form otherwise resolve the method to call in the concrete class using the set MethodNameResolver

Subclasses must implement the methods setup to respond the the various submit buttons.

Consider the following config file: <bean id="submitActionParamResolver" class="uk.co.lakesidetech.springframework.web.servlet.mvc.multiaction.SubmitParameterPropertiesMethodNameResolver"> <property name="mappings”> <props> <prop key="_addOrganisation">addOrganisationSubmit</prop> <prop key="_addCapability">addCapabilitySubmit</prop> <prop key="_cancel">cancelSubmit</prop> <prop key="_finish">finalSubmit</prop> </props> </property> <property name="defaultMethodName"> <value>finalSubmit</value> </property>

The subclass would need to contain the methods: public void addOrganisationSubmit(HttpServletRequest request,Object command, BindException errors) public void addCapabilitySubmit(HttpServletRequest request,Object command, BindException errors) public void finalSubmit(HttpServletRequest request,Object command, BindException errors)

If the form submission object returns a ModelAndView object then this is considered the user response and that ModelAndView is rendered otherwise the showForm is rendered to show the returned form.

Parameters:
request - the request object
response - the response object
command - the command object
errors - bind errors object
Returns:
the model and view to be used in display
Throws:
java.lang.Exception
See Also:
AbstractFormController.processFormSubmission(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)