Thanks to Erwin Bolwidt for submitting the original prototype
of such a cancellable form controller!
| Method from org.springframework.web.servlet.mvc.CancellableFormController Detail: |
public final String getCancelParamKey() {
return this.cancelParamKey;
}
Return the key of the request parameter used to identify a cancel request. |
public final String getCancelView() {
return this.cancelView;
}
Gets the name of the cancel view. |
protected boolean isCancelRequest(HttpServletRequest request) {
return WebUtils.hasSubmitParameter(request, getCancelParamKey());
}
Determine whether the incoming request is a request to cancel the
processing of the current form.
By default, this method returns true if a parameter
matching the configured cancelParamKey is present in
the request, otherwise it returns false. Subclasses may
override this method to provide custom logic to detect a cancel request.
The parameter is recognized both when sent as a plain parameter
("_cancel") or when triggered by an image button ("_cancel.x"). |
protected boolean isFormSubmission(HttpServletRequest request) {
return super.isFormSubmission(request) || isCancelRequest(request);
}
Consider an explicit cancel request as a form submission too. |
protected ModelAndView onCancel(Object command) throws Exception {
return new ModelAndView(getCancelView());
}
Simple onCancel version. Called by the default implementation
of the onCancel version with all parameters.
Default implementation returns eturns the configured cancelView.
Subclasses may override this method to build a custom ModelAndView
that may contain model parameters used in the cancel view.
If you simply want to move the user to a new view and you don't want to add
additional model parameters, use #setCancelView(String) rather than
overriding an onCancel method. |
protected ModelAndView onCancel(HttpServletRequest request,
HttpServletResponse response,
Object command) throws Exception {
return onCancel(command);
}
Callback method for handling a cancel request. Called if #isCancelRequest
returns true.
Default implementation delegates to onCancel(Object) to return
the configured cancelView. Subclasses may override either of the two
methods to build a custom ModelAndView that may contain model
parameters used in the cancel view.
If you simply want to move the user to a new view and you don't want to add
additional model parameters, use #setCancelView(String) rather than
overriding an onCancel method. |
protected ModelAndView processFormSubmission(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
if (isCancelRequest(request)) {
return onCancel(request, response, command);
}
else {
return super.processFormSubmission(request, response, command, errors);
}
}
|
public final void setCancelParamKey(String cancelParamKey) {
this.cancelParamKey = cancelParamKey;
}
Set the key of the request parameter used to identify a cancel request.
Default is "_cancel".
The parameter is recognized both when sent as a plain parameter
("_cancel") or when triggered by an image button ("_cancel.x"). |
public final void setCancelView(String cancelView) {
this.cancelView = cancelView;
}
Sets the name of the cancel view. |
protected boolean suppressValidation(HttpServletRequest request,
Object command) {
return super.suppressValidation(request, command) || isCancelRequest(request);
}
Suppress validation for an explicit cancel request too. |