java.lang.Objectorg.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.support.WebContentGenerator
org.springframework.web.servlet.mvc.AbstractController
org.springframework.web.servlet.mvc.BaseCommandController
org.springframework.web.servlet.mvc.AbstractFormController
org.springframework.web.servlet.mvc.SimpleFormController
All Implemented Interfaces:
Controller, ServletContextAware, ApplicationContextAware
Direct Known Subclasses:
CancellableFormController
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):
successView. Consider implementing #doSubmitAction 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. |
| Fields inherited from org.springframework.web.servlet.mvc.BaseCommandController: |
|---|
| DEFAULT_COMMAND_NAME |
| Fields inherited from org.springframework.web.servlet.support.WebContentGenerator: |
|---|
| METHOD_GET, METHOD_HEAD, METHOD_POST |
| Fields inherited from org.springframework.context.support.ApplicationObjectSupport: |
|---|
| logger |
| Constructor: |
|---|
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
|
| Method from org.springframework.web.servlet.mvc.SimpleFormController Summary: |
|---|
| doSubmitAction, getFormView, getSuccessView, isFormChangeRequest, isFormChangeRequest, onFormChange, onFormChange, onSubmit, onSubmit, onSubmit, processFormSubmission, referenceData, referenceData, setFormView, setSuccessView, showForm, showForm, suppressValidation |
| Methods from org.springframework.web.servlet.mvc.AbstractFormController: |
|---|
| currentFormObject, formBackingObject, getCommand, getErrorsForNewForm, getFormSessionAttributeName, getFormSessionAttributeName, handleInvalidSubmit, handleRequestInternal, isBindOnNewForm, isFormSubmission, isSessionForm, onBindOnNewForm, onBindOnNewForm, processFormSubmission, referenceData, setBindOnNewForm, setSessionForm, showForm, showForm, showForm, showNewForm |
| Methods from org.springframework.web.servlet.mvc.AbstractController: |
|---|
| handleRequest, handleRequestInternal, isSynchronizeOnSession, setSynchronizeOnSession |
| Methods from org.springframework.web.servlet.support.WebContentGenerator: |
|---|
| applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader |
| Methods from org.springframework.web.context.support.WebApplicationObjectSupport: |
|---|
| getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext |
| Methods from org.springframework.context.support.ApplicationObjectSupport: |
|---|
| getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, requiredContextClass, setApplicationContext |
| Methods from java.lang.Object: |
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.springframework.web.servlet.mvc.SimpleFormController Detail: |
|---|
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. |
|
|
isFormChangeRequest variant, called by the full
variant #isFormChangeRequest(HttpServletRequest, Object) .
The default implementation returns |
Gets called by #suppressValidation and #processFormSubmission . 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) . |
onFormChange variant, called by the full variant
#onFormChange(HttpServletRequest, HttpServletResponse, Object, BindException) .
The default implementation is empty. |
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) . |
onSubmit variant. Called by the default implementation
of the #onSubmit(Object, BindException) variant.
This implementation calls #doSubmitAction(Object) and returns
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. |
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 |
The default implementation delegates to #onSubmit(Object, BindException) .
For simply performing a submit action and rendering the specified success
view, consider implementing #doSubmitAction rather than an
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 |
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 |
The default implementation returns |
The default implementation delegates to #referenceData(HttpServletRequest) . Subclasses can override this to set reference data used in the view. |
|
|
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). |
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. |
|