org.springframework.web.servlet.mvc
@Deprecated public abstract class AbstractWizardFormController extends AbstractFormController
In contrast to classic forms, wizards have more than one form view page. Therefore, there are various actions instead of one single submit action:
Finish and cancel actions can be triggered by request parameters, named PARAM_FINISH ("_finish") and PARAM_CANCEL ("_cancel"), ignoring parameter values to allow for HTML buttons. The target page for page changes can be specified by PARAM_TARGET, appending the page number to the parameter name (e.g. "_target1"). The action parameters are recognized when triggered by image buttons too (via "_finish.x", "_abort.x", or "_target1.x").
The current page number will be stored in the session. It can also be specified as request parameter PARAM_PAGE ("_page") in order to properly handle usage of the back button in a browser: In this case, a submission will always contain the correct page number, even if the user submitted from an old view.
The page can only be changed if it validates correctly, except if a "dirty back" or "dirty forward" is allowed. At finish, all pages get validated again to guarantee a consistent state.
Note that a validator's default validate method is not executed when using
this class! Rather, the validatePage(java.lang.Object, org.springframework.validation.Errors, int, boolean)
implementation should call
special validateXXX
methods that the validator needs to provide,
validating certain pieces of the object. These can be combined to validate
the elements of individual pages.
Note: Page numbering starts with 0, to be able to pass an array consisting of the corresponding view names to the "pages" bean property.
setPages(java.lang.String[])
,
validatePage(java.lang.Object, org.springframework.validation.Errors, int, boolean)
,
processFinish(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
,
processCancel(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
Modifier and Type | Field and Description |
---|---|
static String |
PARAM_CANCEL
Deprecated.
Parameter triggering the cancel action.
|
static String |
PARAM_FINISH
Deprecated.
Parameter triggering the finish action.
|
static String |
PARAM_PAGE
Deprecated.
Parameter specifying the current page as value.
|
static String |
PARAM_TARGET
Deprecated.
Parameter specifying the target page,
appending the page number to the name.
|
DEFAULT_COMMAND_NAME
Constructor and Description |
---|
AbstractWizardFormController()
Deprecated.
Create a new AbstractWizardFormController.
|
Modifier and Type | Method and Description |
---|---|
protected int |
getCurrentPage(javax.servlet.http.HttpServletRequest request)
Deprecated.
Return the current page number.
|
protected int |
getInitialPage(javax.servlet.http.HttpServletRequest request)
Deprecated.
Return the initial page of the wizard, that is, the page shown at wizard startup.
|
protected int |
getInitialPage(javax.servlet.http.HttpServletRequest request,
Object command)
Deprecated.
Return the initial page of the wizard, that is, the page shown at wizard startup.
|
String |
getPageAttribute()
Deprecated.
Return the name of the page attribute in the model.
|
protected int |
getPageCount()
Deprecated.
Return the number of wizard pages.
|
protected int |
getPageCount(javax.servlet.http.HttpServletRequest request,
Object command)
Deprecated.
Return the page count for this wizard form controller.
|
String[] |
getPages()
Deprecated.
Return the wizard pages, i.e.
|
protected String |
getPageSessionAttributeName()
Deprecated.
Return the name of the HttpSession attribute that holds the page object
for this wizard form controller.
|
protected String |
getPageSessionAttributeName(javax.servlet.http.HttpServletRequest request)
Deprecated.
Return the name of the HttpSession attribute that holds the page object
for this wizard form controller.
|
protected int |
getTargetPage(javax.servlet.http.HttpServletRequest request,
int currentPage)
Deprecated.
Return the target page specified in the request.
|
protected int |
getTargetPage(javax.servlet.http.HttpServletRequest request,
Object command,
org.springframework.validation.Errors errors,
int currentPage)
Deprecated.
Return the target page specified in the request.
|
protected String |
getViewName(javax.servlet.http.HttpServletRequest request,
Object command,
int page)
Deprecated.
Return the name of the view for the specified page of this wizard form controller.
|
protected org.springframework.web.servlet.ModelAndView |
handleInvalidSubmit(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Deprecated.
Handle an invalid submit request, e.g.
|
boolean |
isAllowDirtyBack()
Deprecated.
Return whether "dirty back" is allowed.
|
boolean |
isAllowDirtyForward()
Deprecated.
Return whether "dirty forward" is allowed.
|
protected boolean |
isCancelRequest(javax.servlet.http.HttpServletRequest request)
Deprecated.
Determine whether the incoming request is a request to cancel the
processing of the current form.
|
protected boolean |
isFinishRequest(javax.servlet.http.HttpServletRequest request)
Deprecated.
Determine whether the incoming request is a request to finish the
processing of the current form.
|
protected boolean |
isFormSubmission(javax.servlet.http.HttpServletRequest request)
Deprecated.
Consider an explicit finish or cancel request as a form submission too.
|
protected void |
onBindAndValidate(javax.servlet.http.HttpServletRequest request,
Object command,
org.springframework.validation.BindException errors)
Deprecated.
Calls page-specific onBindAndValidate method.
|
protected void |
onBindAndValidate(javax.servlet.http.HttpServletRequest request,
Object command,
org.springframework.validation.BindException errors,
int page)
Deprecated.
Callback for custom post-processing in terms of binding and validation.
|
protected void |
postProcessPage(javax.servlet.http.HttpServletRequest request,
Object command,
org.springframework.validation.Errors errors,
int page)
Deprecated.
Post-process the given page after binding and validation, potentially
updating its command object.
|
protected org.springframework.web.servlet.ModelAndView |
processCancel(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Object command,
org.springframework.validation.BindException errors)
Deprecated.
Template method for processing the cancel action of this wizard.
|
protected abstract org.springframework.web.servlet.ModelAndView |
processFinish(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Object command,
org.springframework.validation.BindException errors)
Deprecated.
Template method for processing the final action of this wizard.
|
protected org.springframework.web.servlet.ModelAndView |
processFormSubmission(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Object command,
org.springframework.validation.BindException errors)
Deprecated.
Apply wizard workflow: finish, cancel, page change.
|
protected Map |
referenceData(javax.servlet.http.HttpServletRequest request,
int page)
Deprecated.
Create a reference data map for the given request, consisting of
bean name/bean instance pairs as expected by ModelAndView.
|
protected Map |
referenceData(javax.servlet.http.HttpServletRequest request,
Object command,
org.springframework.validation.Errors errors)
Deprecated.
Calls page-specific referenceData method.
|
protected Map |
referenceData(javax.servlet.http.HttpServletRequest request,
Object command,
org.springframework.validation.Errors errors,
int page)
Deprecated.
Create a reference data map for the given request, consisting of
bean name/bean instance pairs as expected by ModelAndView.
|
void |
setAllowDirtyBack(boolean allowDirtyBack)
Deprecated.
Set if "dirty back" is allowed, that is, if moving to a former wizard
page is allowed in case of validation errors for the current page.
|
void |
setAllowDirtyForward(boolean allowDirtyForward)
Deprecated.
Set if "dirty forward" is allowed, that is, if moving to a later wizard
page is allowed in case of validation errors for the current page.
|
void |
setPageAttribute(String pageAttribute)
Deprecated.
Set the name of the page attribute in the model, containing
an Integer with the current page number.
|
void |
setPages(String[] pages)
Deprecated.
Set the wizard pages, i.e.
|
protected org.springframework.web.servlet.ModelAndView |
showForm(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.validation.BindException errors)
Deprecated.
Show the first page as form view.
|
protected org.springframework.web.servlet.ModelAndView |
showPage(javax.servlet.http.HttpServletRequest request,
org.springframework.validation.BindException errors,
int page)
Deprecated.
Prepare the form model and view, including reference and error data,
for the given page.
|
protected void |
validatePage(Object command,
org.springframework.validation.Errors errors,
int page)
Deprecated.
Template method for custom validation logic for individual pages.
|
protected void |
validatePage(Object command,
org.springframework.validation.Errors errors,
int page,
boolean finish)
Deprecated.
Template method for custom validation logic for individual pages.
|
currentFormObject, formBackingObject, getCommand, getErrorsForNewForm, getFormSessionAttributeName, getFormSessionAttributeName, handleRequestInternal, isBindOnNewForm, 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, prepareBinder, setBindingErrorProcessor, setCommandClass, setCommandName, setMessageCodesResolver, setPropertyEditorRegistrar, setPropertyEditorRegistrars, setValidateOnBinding, setValidator, setValidators, setWebBindingInitializer, suppressBinding, suppressValidation, 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
public static final String PARAM_FINISH
public static final String PARAM_CANCEL
public static final String PARAM_TARGET
public static final String PARAM_PAGE
public AbstractWizardFormController()
"sessionForm" is automatically turned on, "validateOnBinding" turned off, and "cacheSeconds" set to 0 by the base class (-> no caching for all form controllers).
public final void setPages(String[] pages)
pages
- view names for the pagespublic final String[] getPages()
Note that a concrete wizard form controller might override
getViewName(HttpServletRequest, Object, int)
to
determine the view name for each page dynamically.
protected final int getPageCount()
Note that a concrete wizard form controller might override
getPageCount(HttpServletRequest, Object)
to determine
the page count dynamically. The default implementation of that extended
getPageCount
variant returns the static page count as
determined by this getPageCount()
method.
public final void setPageAttribute(String pageAttribute)
This will be necessary for single views rendering multiple view pages. It also allows for specifying the optional "_page" parameter.
pageAttribute
- name of the page attributePARAM_PAGE
public final String getPageAttribute()
public final void setAllowDirtyBack(boolean allowDirtyBack)
allowDirtyBack
- if "dirty back" is allowedpublic final boolean isAllowDirtyBack()
public final void setAllowDirtyForward(boolean allowDirtyForward)
allowDirtyForward
- if "dirty forward" is allowedpublic final boolean isAllowDirtyForward()
protected final void onBindAndValidate(javax.servlet.http.HttpServletRequest request, Object command, org.springframework.validation.BindException errors) throws Exception
onBindAndValidate
in class BaseCommandController
request
- current HTTP requestcommand
- the command object, still allowing for further bindingerrors
- validation errors holder, allowing for additional
custom validationException
- in case of invalid state or argumentsBaseCommandController.bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object)
,
Errors
protected void onBindAndValidate(javax.servlet.http.HttpServletRequest request, Object command, org.springframework.validation.BindException errors, int page) throws Exception
Note: AbstractWizardFormController does not perform standand validation on binding but rather applies page-specific validation on processing the form submission.
request
- current HTTP requestcommand
- bound commanderrors
- Errors instance for additional custom validationpage
- current wizard pageException
- in case of invalid state or argumentsBaseCommandController.bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object)
,
processFormSubmission(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
,
Errors
protected boolean isFormSubmission(javax.servlet.http.HttpServletRequest request)
isFormSubmission
in class AbstractFormController
request
- current HTTP requestisFinishRequest(javax.servlet.http.HttpServletRequest)
,
isCancelRequest(javax.servlet.http.HttpServletRequest)
protected final Map referenceData(javax.servlet.http.HttpServletRequest request, Object command, org.springframework.validation.Errors errors) throws Exception
referenceData
in class AbstractFormController
request
- current HTTP requestcommand
- form object with request parameters bound onto iterrors
- validation errors holdernull
if noneException
- in case of invalid state or argumentsModelAndView
protected Map referenceData(javax.servlet.http.HttpServletRequest request, Object command, org.springframework.validation.Errors errors, int page) throws Exception
The default implementation delegates to referenceData(HttpServletRequest, int). Subclasses can override this to set reference data used in the view.
request
- current HTTP requestcommand
- form object with request parameters bound onto iterrors
- validation errors holderpage
- current wizard pagenull
if noneException
- in case of invalid state or argumentsreferenceData(HttpServletRequest, int)
,
ModelAndView
protected Map referenceData(javax.servlet.http.HttpServletRequest request, int page) throws Exception
The default implementation returns null
.
Subclasses can override this to set reference data used in the view.
request
- current HTTP requestpage
- current wizard pagenull
if noneException
- in case of invalid state or argumentsModelAndView
protected org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.validation.BindException errors) throws Exception
This can be overridden in subclasses, e.g. to prepare wizard-specific error views in case of an Exception.
showForm
in class AbstractFormController
request
- current HTTP requestresponse
- current HTTP responseerrors
- validation errors holdernull
if handled directlyException
- in case of invalid state or argumentsAbstractFormController.showForm(HttpServletRequest, BindException, String)
,
Errors
,
BindException.getModel()
,
AbstractFormController.referenceData(HttpServletRequest, Object, Errors)
,
SimpleFormController.setFormView(java.lang.String)
protected final org.springframework.web.servlet.ModelAndView showPage(javax.servlet.http.HttpServletRequest request, org.springframework.validation.BindException errors, int page) throws Exception
processFinish(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
implementations,
to show the corresponding page in case of validation errors.request
- current HTTP requesterrors
- validation errors holderpage
- number of page to showException
- in case of invalid state or argumentsprotected int getPageCount(javax.servlet.http.HttpServletRequest request, Object command)
getPageCount()
.
Can be overridden to dynamically adapt the page count.
request
- current HTTP requestcommand
- the command object as returned by formBackingObjectgetPageCount()
protected String getViewName(javax.servlet.http.HttpServletRequest request, Object command, int page)
The default implementation takes the view name from the getPages()
array.
Can be overridden to dynamically switch the page view or to return view names for dynamically defined pages.
request
- current HTTP requestcommand
- the command object as returned by formBackingObjectpage
- the current page numbergetPageCount()
protected int getInitialPage(javax.servlet.http.HttpServletRequest request, Object command)
The default implementation delegates to getInitialPage(HttpServletRequest)
.
request
- current HTTP requestcommand
- the command object as returned by formBackingObjectgetInitialPage(HttpServletRequest)
,
AbstractFormController.formBackingObject(javax.servlet.http.HttpServletRequest)
protected int getInitialPage(javax.servlet.http.HttpServletRequest request)
The default implementation returns 0 for first page.
request
- current HTTP requestprotected String getPageSessionAttributeName(javax.servlet.http.HttpServletRequest request)
The default implementation delegates to the getPageSessionAttributeName()
variant without arguments.
request
- current HTTP requestnull
if not in session form modegetPageSessionAttributeName(javax.servlet.http.HttpServletRequest)
,
AbstractFormController.getFormSessionAttributeName(javax.servlet.http.HttpServletRequest)
,
HttpSession.getAttribute(java.lang.String)
protected String getPageSessionAttributeName()
Default is an internal name, of no relevance to applications, as the form session attribute is not usually accessed directly. Can be overridden to use an application-specific attribute name, which allows other code to access the session attribute directly.
AbstractFormController.getFormSessionAttributeName(javax.servlet.http.HttpServletRequest)
,
HttpSession.getAttribute(java.lang.String)
protected org.springframework.web.servlet.ModelAndView handleInvalidSubmit(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
The default implementation for wizard form controllers simply shows the initial page of a new wizard form. If you want to show some "invalid submit" message, you need to override this method.
handleInvalidSubmit
in class AbstractFormController
request
- current HTTP requestresponse
- current HTTP responsenull
if handled directlyException
- in case of errorsAbstractFormController.showNewForm(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,
AbstractFormController.setBindOnNewForm(boolean)
protected final org.springframework.web.servlet.ModelAndView processFormSubmission(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object command, org.springframework.validation.BindException errors) throws Exception
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
Exception
- in case of errorsAbstractFormController.handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,
AbstractFormController.isFormSubmission(javax.servlet.http.HttpServletRequest)
,
AbstractFormController.showForm(HttpServletRequest, HttpServletResponse, BindException)
,
Errors
,
BindException.getModel()
protected int getCurrentPage(javax.servlet.http.HttpServletRequest request)
processFormSubmission(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
.
The default implementation checks the page session attribute. Subclasses can override this for customized page determination.
request
- current HTTP requestgetPageSessionAttributeName()
protected boolean isFinishRequest(javax.servlet.http.HttpServletRequest request)
By default, this method returns true
if a parameter
matching the "_finish" key is present in the request, otherwise it
returns false
. Subclasses may override this method
to provide custom logic to detect a finish request.
The parameter is recognized both when sent as a plain parameter ("_finish") or when triggered by an image button ("_finish.x").
request
- current HTTP requestPARAM_FINISH
protected boolean isCancelRequest(javax.servlet.http.HttpServletRequest request)
By default, this method returns true
if a parameter
matching the "_cancel" key 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").
request
- current HTTP requestPARAM_CANCEL
protected int getTargetPage(javax.servlet.http.HttpServletRequest request, Object command, org.springframework.validation.Errors errors, int currentPage)
The default implementation delegates to getTargetPage(HttpServletRequest, int)
.
Subclasses can override this for customized target page determination.
request
- current HTTP requestcommand
- form object with request parameters bound onto iterrors
- validation errors holdercurrentPage
- the current page, to be returned as fallback
if no target page specifiedgetTargetPage(HttpServletRequest, int)
protected int getTargetPage(javax.servlet.http.HttpServletRequest request, int currentPage)
The default implementation examines "_target" parameter (e.g. "_target1"). Subclasses can override this for customized target page determination.
request
- current HTTP requestcurrentPage
- the current page, to be returned as fallback
if no target page specifiedPARAM_TARGET
protected void validatePage(Object command, org.springframework.validation.Errors errors, int page, boolean finish)
validatePage(Object, Errors, int)
.
Implementations will typically call fine-granular validateXXX
methods of this instance's Validator, combining them to validation of the
corresponding pages. The Validator's default validate
method
will not be called by a wizard form controller!
command
- form object with the current wizard stateerrors
- validation errors holderpage
- number of page to validatefinish
- whether this method is called during final revalidation on finish
(else, it is called for validating the current page)validatePage(Object, Errors, int)
,
Validator.validate(java.lang.Object, org.springframework.validation.Errors)
protected void validatePage(Object command, org.springframework.validation.Errors errors, int page)
Implementations will typically call fine-granular validateXXX methods of this
instance's validator, combining them to validation of the corresponding pages.
The validator's default validate
method will not be called by a
wizard form controller!
command
- form object with the current wizard stateerrors
- validation errors holderpage
- number of page to validateValidator.validate(java.lang.Object, org.springframework.validation.Errors)
protected void postProcessPage(javax.servlet.http.HttpServletRequest request, Object command, org.springframework.validation.Errors errors, int page) throws Exception
Only invoked when displaying another page or the same page again, not when finishing or cancelling.
request
- current HTTP requestcommand
- form object with request parameters bound onto iterrors
- validation errors holderpage
- number of page to post-processException
- in case of invalid state or argumentsprotected abstract org.springframework.web.servlet.ModelAndView processFinish(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object command, org.springframework.validation.BindException errors) throws Exception
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.
You can call the showPage(javax.servlet.http.HttpServletRequest, org.springframework.validation.BindException, int)
method to return back to the wizard,
in case of last-minute validation errors having been found that you would
like to present to the user within the original wizard form.
request
- current HTTP requestresponse
- current HTTP responsecommand
- form object with the current wizard stateerrors
- validation errors holderException
- in case of invalid state or argumentsErrors
,
BindException.getModel()
,
showPage(javax.servlet.http.HttpServletRequest, org.springframework.validation.BindException, int)
protected org.springframework.web.servlet.ModelAndView processCancel(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object command, org.springframework.validation.BindException errors) throws Exception
The default implementation throws a ServletException, saying that a cancel operation is not supported by this controller. Thus, you do not need to implement this template method if you do not support a cancel operation.
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 HTTP requestresponse
- current HTTP responsecommand
- form object with the current wizard stateerrors
- Errors instance containing errorsException
- in case of invalid state or argumentsErrors
,
BindException.getModel()
Copyright © 2015 OpenMRS Inc.. All Rights Reserved.