@Deprecated public class SimpleFormController extends AbstractFormController
Concrete FormController implementation that provides configurable form and success views, and an onSubmit chain for convenient overriding. Automatically resubmits to the form view in case of validation errors, and renders the success view in case of a valid submission.
The workflow of this Controller does not differ much from the one described
in the AbstractFormController
. The difference
is that you do not need to implement showForm
and
processFormSubmission
: A form view and a
success view can be configured declaratively.
Workflow
(in addition to the superclass):
processFormSubmission
which inspects
the Errors
object to see if
any errors have occurred during binding and validation.isFormChangeRequest
is overridden and returns
true for the given request, the controller will return the formView too.
In that case, the controller will also suppress validation. Before returning the formView,
the controller will invoke onFormChange(HttpServletRequest, HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
, giving sub-classes a chance
to make modification to the command object.
This is intended for requests that change the structure of the form,
which should not cause validation and show the form in any case.onSubmit
using all parameters, which in case of the default implementation delegates to
onSubmit
with just the command object.
The default implementation of the latter method will return the configured
successView
. Consider implementing doSubmitAction(java.lang.Object)
doSubmitAction
for simply performing a submit action and rendering the success view.The submit behavior can be customized by overriding one of the
onSubmit
methods. Submit actions can also perform
custom validation if necessary (typically database-driven checks), calling
showForm
in case of validation errors to show the form view again.
Exposed configuration properties
(and those defined by superclass):
name | default | description |
formView | null | Indicates what view to use when the user asks for a new form or when validation errors have occurred on form submission. |
successView | null | Indicates what view to use when successful form submissions have
occurred. Such a success view could e.g. display a submission summary.
More sophisticated actions can be implemented by overriding one of
the onSubmit() methods. |
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
formView
Deprecated.
|
private java.lang.String |
successView
Deprecated.
|
DEFAULT_COMMAND_NAME
METHOD_GET, METHOD_HEAD, METHOD_POST
logger
Constructor and Description |
---|
SimpleFormController()
Deprecated.
Create a new SimpleFormController.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doSubmitAction(java.lang.Object command)
Deprecated.
Template method for submit actions.
|
java.lang.String |
getFormView()
Deprecated.
Return the name of the view that should be used for form display.
|
java.lang.String |
getSuccessView()
Deprecated.
Return the name of the view that should be shown on successful submit.
|
protected boolean |
isFormChangeRequest(HttpServletRequest request)
Deprecated.
Simpler
isFormChangeRequest variant, called by the full
variant isFormChangeRequest(HttpServletRequest, Object) . |
protected boolean |
isFormChangeRequest(HttpServletRequest request,
java.lang.Object command)
Deprecated.
Determine whether the given request is a form change request.
|
protected void |
onFormChange(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object command)
Deprecated.
Simpler
onFormChange variant, called by the full variant
onFormChange(HttpServletRequest, HttpServletResponse, Object, BindException) . |
protected void |
onFormChange(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object command,
BindException errors)
Deprecated.
Called during form submission if
#isFormChangeRequest(javax.servlet.http.HttpServletRequest)
returns true . |
protected ModelAndView |
onSubmit(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object command,
BindException errors)
Deprecated.
Submit callback with all parameters.
|
protected ModelAndView |
onSubmit(java.lang.Object command)
Deprecated.
Simplest
onSubmit variant. |
protected ModelAndView |
onSubmit(java.lang.Object command,
BindException errors)
Deprecated.
Simpler
onSubmit variant. |
protected ModelAndView |
processFormSubmission(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object command,
BindException errors)
Deprecated.
This implementation calls
showForm(HttpServletRequest, HttpServletResponse, BindException)
in case of errors, and delegates to the full
onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException) 's
variant else. |
protected java.util.Map |
referenceData(HttpServletRequest request)
Deprecated.
Create a reference data map for the given request.
|
protected java.util.Map |
referenceData(HttpServletRequest request,
java.lang.Object command,
Errors errors)
Deprecated.
Create a reference data map for the given request and command,
consisting of bean name/bean instance pairs as expected by ModelAndView.
|
void |
setFormView(java.lang.String formView)
Deprecated.
Set the name of the view that should be used for form display.
|
void |
setSuccessView(java.lang.String successView)
Deprecated.
Set the name of the view that should be shown on successful submit.
|
protected ModelAndView |
showForm(HttpServletRequest request,
HttpServletResponse response,
BindException errors)
Deprecated.
This implementation shows the configured form view, delegating to the analogous
showForm(HttpServletRequest, HttpServletResponse, BindException, Map)
variant with a "controlModel" argument. |
protected ModelAndView |
showForm(HttpServletRequest request,
HttpServletResponse response,
BindException errors,
java.util.Map controlModel)
Deprecated.
This implementation shows the configured form view.
|
protected boolean |
suppressValidation(HttpServletRequest request,
java.lang.Object command)
Deprecated.
This implementation delegates to
isFormChangeRequest(HttpServletRequest, Object) :
A form change request changes the appearance of the form and should not get
validated but just show the new form. |
currentFormObject, formBackingObject, getCommand, getErrorsForNewForm, getFormSessionAttributeName, getFormSessionAttributeName, handleInvalidSubmit, handleRequestInternal, isBindOnNewForm, isFormSubmission, isSessionForm, onBindOnNewForm, onBindOnNewForm, setBindOnNewForm, setSessionForm, showForm, showForm, showNewForm
bindAndValidate, checkCommand, createBinder, createCommand, getBindingErrorProcessor, getCommandClass, getCommandName, getMessageCodesResolver, getPropertyEditorRegistrars, getValidator, getValidators, getWebBindingInitializer, initApplicationContext, initBinder, isValidateOnBinding, onBind, onBind, onBindAndValidate, prepareBinder, setBindingErrorProcessor, setCommandClass, setCommandName, setMessageCodesResolver, setPropertyEditorRegistrar, setPropertyEditorRegistrars, setValidateOnBinding, setValidator, setValidators, setWebBindingInitializer, suppressBinding, suppressValidation, suppressValidation, useDirectFieldAccess
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setAlwaysMustRevalidate, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
private java.lang.String formView
private java.lang.String successView
public SimpleFormController()
Subclasses should set the following properties, either in the constructor
or via a BeanFactory: commandName, commandClass, sessionForm, formView,
successView. Note that commandClass doesn't need to be set when overriding
formBackingObject
, as this determines the class anyway.
public final void setFormView(java.lang.String formView)
public final java.lang.String getFormView()
public final void setSuccessView(java.lang.String successView)
public final java.lang.String getSuccessView()
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws java.lang.Exception
showForm(HttpServletRequest, HttpServletResponse, BindException, Map)
variant with a "controlModel" argument.
Can be called within
onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
implementations, to redirect back to the form in case of custom validation errors
(errors not determined by the validator).
Can be overridden in subclasses to show a custom view, writing directly to the response or preparing the response before rendering a view.
If calling showForm with a custom control model in subclasses, it's preferable to override the analogous showForm version with a controlModel argument (which will handle both standard form showing and custom form showing then).
showForm
in class AbstractFormController
request
- current HTTP requestresponse
- current HTTP responseerrors
- validation errors holdernull
if handled directlyjava.lang.Exception
- in case of invalid state or argumentssetFormView(java.lang.String)
,
showForm(HttpServletRequest, HttpServletResponse, BindException, Map)
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors, java.util.Map controlModel) throws java.lang.Exception
Can be called within
onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
implementations, to redirect back to the form in case of custom validation errors
(errors not determined by the validator).
Can be overridden in subclasses to show a custom view, writing directly to the response or preparing the response before rendering a view.
request
- current HTTP requesterrors
- validation errors holdercontrolModel
- model map containing controller-specific control data
(e.g. current page in wizard-style controllers or special error message)java.lang.Exception
- in case of invalid state or argumentssetFormView(java.lang.String)
protected java.util.Map referenceData(HttpServletRequest request, java.lang.Object command, Errors errors) throws java.lang.Exception
The default implementation delegates to referenceData(HttpServletRequest)
.
Subclasses can override this to set reference data used in the view.
referenceData
in class AbstractFormController
request
- current HTTP requestcommand
- form object with request parameters bound onto iterrors
- validation errors holdernull
if nonejava.lang.Exception
- in case of invalid state or argumentsModelAndView
protected java.util.Map referenceData(HttpServletRequest request) throws java.lang.Exception
referenceData(HttpServletRequest, Object, Errors)
variant with all parameters.
The default implementation returns null
.
Subclasses can override this to set reference data used in the view.
request
- current HTTP requestnull
if nonejava.lang.Exception
- in case of invalid state or argumentsreferenceData(HttpServletRequest, Object, Errors)
,
ModelAndView
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, java.lang.Object command, BindException errors) throws java.lang.Exception
showForm(HttpServletRequest, HttpServletResponse, BindException)
in case of errors, and delegates to the full
onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
's
variant else.
This can only be overridden to check for an action that should be executed
without respect to binding errors, like a cancel action. To just handle successful
submissions without binding errors, override one of the onSubmit
methods or doSubmitAction(java.lang.Object)
.
processFormSubmission
in class AbstractFormController
request
- current servlet requestresponse
- current servlet responsecommand
- form object with request parameters bound onto iterrors
- holder without errors (subclass can add errors if it wants to)null
java.lang.Exception
- in case of errorsshowForm(HttpServletRequest, HttpServletResponse, BindException)
,
onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
,
onSubmit(Object, BindException)
,
onSubmit(Object)
,
doSubmitAction(Object)
protected boolean suppressValidation(HttpServletRequest request, java.lang.Object command)
isFormChangeRequest(HttpServletRequest, Object)
:
A form change request changes the appearance of the form and should not get
validated but just show the new form.suppressValidation
in class BaseCommandController
request
- current HTTP requestcommand
- the command object to validateisFormChangeRequest(HttpServletRequest, java.lang.Object)
protected boolean isFormChangeRequest(HttpServletRequest request, java.lang.Object command)
Gets called by suppressValidation(HttpServletRequest, java.lang.Object)
and processFormSubmission(HttpServletRequest, HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
.
Consequently, this single method determines to suppress validation
and to show the form view in any case.
The default implementation delegates to
#isFormChangeRequest(javax.servlet.http.HttpServletRequest)
.
request
- current HTTP requestcommand
- form object with request parameters bound onto itsuppressValidation(HttpServletRequest, java.lang.Object)
,
processFormSubmission(HttpServletRequest, HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
protected boolean isFormChangeRequest(HttpServletRequest request)
isFormChangeRequest
variant, called by the full
variant isFormChangeRequest(HttpServletRequest, Object)
.
The default implementation returns false
.
request
- current HTTP requestsuppressValidation(HttpServletRequest, java.lang.Object)
,
processFormSubmission(HttpServletRequest, HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
protected void onFormChange(HttpServletRequest request, HttpServletResponse response, java.lang.Object command, BindException errors) throws java.lang.Exception
#isFormChangeRequest(javax.servlet.http.HttpServletRequest)
returns true
. Allows subclasses to implement custom logic
to modify the command object to directly modify data in the form.
The default implementation delegates to
onFormChange(HttpServletRequest, HttpServletResponse, Object, BindException)
.
request
- current servlet requestresponse
- current servlet responsecommand
- form object with request parameters bound onto iterrors
- validation errors holder, allowing for additional
custom validationjava.lang.Exception
- in case of errorsisFormChangeRequest(HttpServletRequest)
,
onFormChange(HttpServletRequest, HttpServletResponse, Object)
protected void onFormChange(HttpServletRequest request, HttpServletResponse response, java.lang.Object command) throws java.lang.Exception
onFormChange
variant, called by the full variant
onFormChange(HttpServletRequest, HttpServletResponse, Object, BindException)
.
The default implementation is empty.
request
- current servlet requestresponse
- current servlet responsecommand
- form object with request parameters bound onto itjava.lang.Exception
- in case of errorsonFormChange(HttpServletRequest, HttpServletResponse, Object, BindException)
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, java.lang.Object command, BindException errors) throws java.lang.Exception
The default implementation delegates to onSubmit(Object, BindException)
.
For simply performing a submit action and rendering the specified success
view, consider implementing doSubmitAction(java.lang.Object)
rather than an
onSubmit
variant.
Subclasses can override this to provide custom submission handling like storing the object to the database. Implementations can also perform custom validation and call showForm to return to the form. Do not implement multiple onSubmit methods: In that case, just this method will be called by the controller.
Call errors.getModel()
to populate the ModelAndView model
with the command and the Errors instance, under the specified command name,
as expected by the "spring:bind" tag.
request
- current servlet requestresponse
- current servlet responsecommand
- form object with request parameters bound onto iterrors
- Errors instance without errors (subclass can add errors if it wants to)null
java.lang.Exception
- in case of errorsonSubmit(Object, BindException)
,
doSubmitAction(java.lang.Object)
,
showForm(HttpServletRequest, HttpServletResponse, org.springframework.validation.BindException)
,
Errors
,
BindException.getModel()
protected ModelAndView onSubmit(java.lang.Object command, BindException errors) throws java.lang.Exception
onSubmit
variant.
Called by the default implementation of the
onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
variant with all parameters.
The default implementation calls onSubmit(Object)
, using the
returned ModelAndView if actually implemented in a subclass. Else, the
default behavior will apply: rendering the success view with the command
and Errors instance as model.
Subclasses can override this to provide custom submission handling that does not need request and response.
Call errors.getModel()
to populate the ModelAndView model
with the command and the Errors instance, under the specified command name,
as expected by the "spring:bind" tag.
command
- form object with request parameters bound onto iterrors
- Errors instance without errorsjava.lang.Exception
- in case of errorsonSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
,
onSubmit(Object)
,
setSuccessView(java.lang.String)
,
Errors
,
BindException.getModel()
protected ModelAndView onSubmit(java.lang.Object command) throws java.lang.Exception
onSubmit
variant. Called by the default implementation
of the onSubmit(Object, BindException)
variant.
This implementation calls doSubmitAction(Object)
and returns
null
as ModelAndView, making the calling onSubmit
method perform its default rendering of the success view.
Subclasses can override this to provide custom submission handling
that just depends on the command object. It's preferable to use either
onSubmit(Object, BindException)
or doSubmitAction(Object)
,
though: Use the former when you want to build your own ModelAndView; use the
latter when you want to perform an action and forward to the successView.
command
- form object with request parameters bound onto itnull
for default
(that is, rendering the configured "successView")java.lang.Exception
- in case of errorsonSubmit(Object, BindException)
,
doSubmitAction(java.lang.Object)
,
setSuccessView(java.lang.String)
protected void doSubmitAction(java.lang.Object command) throws java.lang.Exception
onSubmit(Object)
variant.
This is the preferred submit callback to implement if you want to perform an action (like storing changes to the database) and then render the success view with the command and Errors instance as model. You don't need to care about the success ModelAndView here.
command
- form object with request parameters bound onto itjava.lang.Exception
- in case of errorsonSubmit(Object)
,
setSuccessView(java.lang.String)