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

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
                      extended byuk.co.lakesidetech.spxforms.web.servlet.mvc.AbstractSpXFormsController
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware, org.springframework.web.servlet.mvc.Controller
Direct Known Subclasses:
AbstractSpXFormsModelViewController, EditXMLFileSpXFormsController, NewDocumentSpXFormsController, XMLDBResourceCreateEditForm

public abstract class AbstractSpXFormsController
extends BaseSpXCommandController

Author:
Stuart Eccles

Field Summary
 
Fields inherited from class uk.co.lakesidetech.spxforms.web.servlet.mvc.BaseSpXCommandController
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
AbstractSpXFormsController()
           
 
Method Summary
protected  boolean checkXFormsCommandClass(java.lang.Object formModel)
           
protected abstract  java.lang.Object formXFormsInstance(javax.servlet.http.HttpServletRequest request)
           
protected  java.lang.Object getCommand(javax.servlet.http.HttpServletRequest request)
          Retrieve a command object for the given request.
protected  java.lang.String getFormSessionAttributeName()
          Return the name of the session attribute that holds the form object for this controller.
protected  java.lang.String getFormView()
          Return the name of the view that should be used for form display.
protected  java.lang.String getSuccessView()
          Return the name of the view that should be shown on successful submit.
protected  org.springframework.web.servlet.ModelAndView handleInvalidSubmit(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 boolean isBindOnNewForm()
           
protected  boolean isFormSubmission(javax.servlet.http.HttpServletRequest request)
          Determine if the given request represents a form submission.
 boolean isSessionForm()
           
protected  org.springframework.web.servlet.ModelAndView processXFormActions(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, org.springframework.validation.BindException errors)
           
protected  org.springframework.web.servlet.ModelAndView processXFormSubmission(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, org.springframework.validation.BindException errors)
           
protected  java.util.Map referenceData(javax.servlet.http.HttpServletRequest request, java.lang.Object command, org.springframework.validation.Errors errors)
          Create a reference data map for the given request, consisting of bean name/bean instance pairs as expected by ModelAndView.
 void setBindOnNewForm(boolean bindOnNewForm)
           
 void setFormView(java.lang.String formView)
          Set the name of the view that should be used for form display.
 void setSessionForm(boolean sessionForm)
           
 void setSuccessView(java.lang.String successView)
          Set the name of the view that should be shown on successful submit.
protected  org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest request, org.springframework.validation.BindException errors, java.lang.String viewName)
          Prepare model and view for the given form, including reference and errors.
protected  org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest request, org.springframework.validation.BindException errors, java.lang.String viewName, java.util.Map controlModel)
          Prepare model and view for the given form, including reference and errors, adding a controller-specific control model.
protected  org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.validation.BindException errors)
          This implementation shows the configured form view.
protected  org.springframework.web.servlet.ModelAndView showNewForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Show a new form.
 
Methods inherited from class uk.co.lakesidetech.spxforms.web.servlet.mvc.BaseSpXCommandController
bindAndValidate, createBinder, createCommand, getCommandClass, getCommandName, getMessageCodesResolver, getValidator, getValidators, initApplicationContext, initBinder, isValidateOnBinding, onBind, onBind, onBindAndValidate, setCommandClass, setCommandName, setMessageCodesResolver, setValidateOnBinding, setValidator, setValidators, suppressValidation
 
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

AbstractSpXFormsController

public AbstractSpXFormsController()
Method Detail

setFormView

public final void setFormView(java.lang.String formView)
Set the name of the view that should be used for form display.


getFormView

protected final java.lang.String getFormView()
Return the name of the view that should be used for form display.


setSuccessView

public final void setSuccessView(java.lang.String successView)
Set the name of the view that should be shown on successful submit.


getSuccessView

protected final java.lang.String getSuccessView()
Return the name of the view that should be shown on successful submit.


handleRequestInternal

protected org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request,
                                                                             javax.servlet.http.HttpServletResponse response)
                                                                      throws java.lang.Exception
Returns:
Throws:
java.lang.Exception
See Also:
AbstractController.handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

processXFormActions

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

isFormSubmission

protected boolean isFormSubmission(javax.servlet.http.HttpServletRequest request)
Determine if the given request represents a form submission.

Default implementation treats a POST request as form submission. Note: If the form session attribute doesn't exist when using session form mode, the request is always treated as new form by handleRequestInternal.

Subclasses can override this to use a custom strategy, e.g. a specific request parameter (assumably a hidden field or submit button name).

Parameters:
request - current HTTP request
Returns:
if the request represents a form submission

isSessionForm

public boolean isSessionForm()
Returns:
Returns the sessionForm.

setSessionForm

public void setSessionForm(boolean sessionForm)
Parameters:
sessionForm - The sessionForm to set.

isBindOnNewForm

public boolean isBindOnNewForm()
Returns:
Returns the bindOnNewForm.

setBindOnNewForm

public void setBindOnNewForm(boolean bindOnNewForm)
Parameters:
bindOnNewForm - The bindOnNewForm to set.

getFormSessionAttributeName

protected final java.lang.String getFormSessionAttributeName()
Return the name of the session attribute that holds the form object for this controller.

Returns:
the name of the form session attribute, or null if not in session form mode.

getCommand

protected final java.lang.Object getCommand(javax.servlet.http.HttpServletRequest request)
                                     throws java.lang.Exception
Description copied from class: BaseSpXCommandController
Retrieve a command object for the given request.

Default implementation calls createCommand. Subclasses can override this.

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

handleInvalidSubmit

protected org.springframework.web.servlet.ModelAndView handleInvalidSubmit(javax.servlet.http.HttpServletRequest request,
                                                                           javax.servlet.http.HttpServletResponse response)
                                                                    throws java.lang.Exception
Throws:
java.lang.Exception

showNewForm

protected final org.springframework.web.servlet.ModelAndView showNewForm(javax.servlet.http.HttpServletRequest request,
                                                                         javax.servlet.http.HttpServletResponse response)
                                                                  throws java.lang.Exception
Show a new form. Prepares a backing object for the current form and the given request, including checking its validity.

Parameters:
request - current HTTP request
response - current HTTP response
Returns:
the prepared form view
Throws:
java.lang.Exception - in case of an invalid new form object

checkXFormsCommandClass

protected boolean checkXFormsCommandClass(java.lang.Object formModel)
Parameters:
formModel -
Returns:

showForm

protected org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest request,
                                                                javax.servlet.http.HttpServletResponse response,
                                                                org.springframework.validation.BindException errors)
                                                         throws java.lang.Exception
This implementation shows the configured form view. Can be called within onSubmit implementations, to redirect back to the form in case of custom validation errors (i.e. not determined by the validator).

Parameters:
request - current HTTP request
response - current HTTP response
errors - validation errors holder
Returns:
the prepared form view, or null if handled directly
Throws:
java.lang.Exception - in case of invalid state or arguments
See Also:
showForm(HttpServletRequest, BindException, String), SimpleFormController#setFormView, setFormView(java.lang.String)

showForm

protected final org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest request,
                                                                      org.springframework.validation.BindException errors,
                                                                      java.lang.String viewName)
                                                               throws java.lang.Exception
Prepare model and view for the given form, including reference and errors. In session form mode: Re-puts the form object in the session when returning to the form, as it has been removed by getCommand. Can be used in subclasses to redirect back to a specific form page.

Parameters:
request - current HTTP request
errors - validation errors holder
viewName - name of the form view
Returns:
the prepared form view
Throws:
java.lang.Exception - in case of invalid state or arguments

showForm

protected final org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest request,
                                                                      org.springframework.validation.BindException errors,
                                                                      java.lang.String viewName,
                                                                      java.util.Map controlModel)
                                                               throws java.lang.Exception
Prepare model and view for the given form, including reference and errors, adding a controller-specific control model. In session form mode: Re-puts the form object in the session when returning to the form, as it has been removed by getCommand. Can be used in subclasses to redirect back to a specific form page.

Parameters:
request - current HTTP request
errors - validation errors holder
viewName - name of the form view
controlModel - model map containing controller-specific control data (e.g. current page in wizard-style controllers).
Returns:
the prepared form view
Throws:
java.lang.Exception - in case of invalid state or arguments

referenceData

protected java.util.Map referenceData(javax.servlet.http.HttpServletRequest request,
                                      java.lang.Object command,
                                      org.springframework.validation.Errors errors)
                               throws java.lang.Exception
Create a reference data map for the given request, consisting of bean name/bean instance pairs as expected by ModelAndView.

Default implementation returns null. Subclasses can override this to set reference data used in the view.

Parameters:
request - current HTTP request
command - form object with request parameters bound onto it
errors - validation errors holder
Returns:
a Map with reference data entries, or null if none
Throws:
java.lang.Exception - in case of invalid state or arguments
See Also:
ModelAndView

formXFormsInstance

protected abstract java.lang.Object formXFormsInstance(javax.servlet.http.HttpServletRequest request)
Parameters:
request -
Returns:

processXFormSubmission

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