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 {@link AbstractFormController AbstractFormController}. The difference is that you do not need to implement {@link #showForm showForm} and{@link #processFormSubmission processFormSubmission}: A form view and a success view can be configured declaratively.
Workflow (in addition to the superclass):
- Call to {@link #processFormSubmission processFormSubmission} which inspectsthe {@link org.springframework.validation.Errors Errors} object to see ifany errors have occurred during binding and validation.
- If errors occured, the controller will return the configured formView, showing the form again (possibly rendering according error messages).
- If {@link #isFormChangeRequest isFormChangeRequest} is overridden and returnstrue 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 {@link #onFormChange}, 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.
- If no errors occurred, the controller will call {@link #onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) onSubmit}using all parameters, which in case of the default implementation delegates to {@link #onSubmit(Object,BindException) onSubmit} with just the command object.The default implementation of the latter method will return the configured
successView
. Consider implementing {@link #doSubmitAction} doSubmitActionfor simply performing a submit action and rendering the success view.
The submit behavior can be customized by overriding one of the {@link #onSubmit onSubmit} methods. Submit actions can also performcustom validation if necessary (typically database-driven checks), calling {@link #showForm(HttpServletRequest,HttpServletResponse,BindException) 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 {@link #onSubmit(Object) onSubmit()} methods. |
@author Juergen Hoeller
@author Rob Harrop
@since 05.05.2003
| public void testPreHandleSucceeds() throws Exception {
AjaxInterceptor ajaxInterceptor = (AjaxInterceptor) this.applicationContext.getBean("ajaxInterceptor");
MockHttpServletRequest httpRequest = new MockHttpServletRequest("GET", "/ajax/test.action");
MockHttpServletResponse httpResponse = new MockHttpServletResponse();
SimpleFormController controller = new SimpleFormController();
httpRequest.setParameter(ajaxInterceptor.getAjaxParameter(), ajaxInterceptor.AJAX_ACTION_REQUEST);
httpRequest.setParameter(ajaxInterceptor.getEventParameter(), "action");
ajaxInterceptor.preHandle(httpRequest, httpResponse, controller);
|
| AjaxInterceptor ajaxInterceptor = (AjaxInterceptor) this.applicationContext.getBean("ajaxInterceptor");
MockHttpServletRequest httpRequest = new MockHttpServletRequest("GET", "/ajax/test.action");
MockHttpServletResponse httpResponse = new MockHttpServletResponse();
ModelAndView mv = new ModelAndView();
SimpleFormController controller = new SimpleFormController();
httpRequest.setParameter(ajaxInterceptor.getAjaxParameter(), ajaxInterceptor.AJAX_ACTION_REQUEST);
httpRequest.setParameter(ajaxInterceptor.getEventParameter(), "fail");
try {
ajaxInterceptor.preHandle(httpRequest, httpResponse, controller);
|
Related Classes of org.springframework.web.servlet.mvc.SimpleFormController
Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact
coftware#gmail.com.