|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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.AbstractWizardFormController
public abstract class AbstractWizardFormController
Form controller for typical wizard-style workflows.
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, to properly handle usage of the back button in a browser: In this case, a submission always contains 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
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)
Field Summary | |
---|---|
static String |
PARAM_CANCEL
Parameter triggering the cancel action. |
static String |
PARAM_FINISH
Parameter triggering the finish action. |
static String |
PARAM_PAGE
Parameter specifying the current page as value. |
static String |
PARAM_TARGET
Parameter specifying the target page, appending the page number to the name. |
Fields inherited from class org.springframework.web.servlet.mvc.BaseCommandController |
---|
DEFAULT_COMMAND_NAME |
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator |
---|
HEADER_CACHE_CONTROL, HEADER_EXPIRES, HEADER_PRAGMA, METHOD_GET, METHOD_HEAD, METHOD_POST |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
logger |
Constructor Summary | |
---|---|
AbstractWizardFormController()
Create a new AbstractWizardFormController. |
Method Summary | |
---|---|
protected int |
getCurrentPage(HttpServletRequest request)
Return the current page number. |
protected int |
getInitialPage(HttpServletRequest request)
Return the initial page of the wizard, i.e. the page shown at wizard startup. |
protected int |
getInitialPage(HttpServletRequest request,
Object command)
Return the initial page of the wizard, i.e. the page shown at wizard startup. |
String |
getPageAttribute()
Return the name of the page attribute in the model. |
protected int |
getPageCount()
Return the number of wizard pages. |
protected int |
getPageCount(HttpServletRequest request,
Object command)
Return the page count for this wizard form controller. |
String[] |
getPages()
Return the wizard pages, i.e. the view names for the pages. |
protected String |
getPageSessionAttributeName()
Return the name of the HttpSession attribute that holds the page object for this wizard form controller. |
protected String |
getPageSessionAttributeName(HttpServletRequest request)
Return the name of the HttpSession attribute that holds the page object for this wizard form controller. |
protected int |
getTargetPage(HttpServletRequest request,
int currentPage)
Return the target page specified in the request. |
protected int |
getTargetPage(HttpServletRequest request,
Object command,
Errors errors,
int currentPage)
Return the target page specified in the request. |
protected String |
getViewName(HttpServletRequest request,
Object command,
int page)
Return the name of the view for the specified page of this wizard form controller. |
protected ModelAndView |
handleInvalidSubmit(HttpServletRequest request,
HttpServletResponse response)
Handle an invalid submit request, e.g. when in session form mode but no form object was found in the session (like in case of an invalid resubmit by the browser). |
boolean |
isAllowDirtyBack()
Return whether "dirty back" is allowed. |
boolean |
isAllowDirtyForward()
Return whether "dirty forward" is allowed. |
protected boolean |
isCancel(HttpServletRequest request)
Deprecated. in favor of isCancelRequest |
protected boolean |
isCancelRequest(HttpServletRequest request)
Determine whether the incoming request is a request to cancel the processing of the current form. |
protected boolean |
isFinish(HttpServletRequest request)
Deprecated. in favor of isFinishRequest |
protected boolean |
isFinishRequest(HttpServletRequest request)
Determine whether the incoming request is a request to finish the processing of the current form. |
protected boolean |
isFormSubmission(HttpServletRequest request)
Consider an explicit finish or cancel request as a form submission too. |
protected void |
onBindAndValidate(HttpServletRequest request,
Object command,
BindException errors)
Calls page-specific onBindAndValidate method. |
protected void |
onBindAndValidate(HttpServletRequest request,
Object command,
BindException errors,
int page)
Callback for custom post-processing in terms of binding and validation. |
protected void |
postProcessPage(HttpServletRequest request,
Object command,
Errors errors,
int page)
Post-process the given page after binding and validation, potentially updating its command object. |
protected ModelAndView |
processCancel(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors)
Template method for processing the cancel action of this wizard. |
protected abstract ModelAndView |
processFinish(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors)
Template method for processing the final action of this wizard. |
protected ModelAndView |
processFormSubmission(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors)
Apply wizard workflow: finish, cancel, page change. |
protected Map |
referenceData(HttpServletRequest request,
int page)
Create a reference data map for the given request, consisting of bean name/bean instance pairs as expected by ModelAndView. |
protected Map |
referenceData(HttpServletRequest request,
Object command,
Errors errors)
Calls page-specific referenceData method. |
protected Map |
referenceData(HttpServletRequest request,
Object command,
Errors errors,
int page)
Create a reference data map for the given request, consisting of bean name/bean instance pairs as expected by ModelAndView. |
void |
setAllowDirtyBack(boolean allowDirtyBack)
Set if "dirty back" is allowed, i.e. if moving to a former wizard page is allowed in case of validation errors for the current page. |
void |
setAllowDirtyForward(boolean allowDirtyForward)
Set if "dirty forward" is allowed, i.e. if moving to a later wizard page is allowed in case of validation errors for the current page. |
void |
setPageAttribute(String pageAttribute)
Set the name of the page attribute in the model, containing an Integer with the current page number. |
void |
setPages(String[] pages)
Set the wizard pages, i.e. the view names for the pages. |
protected ModelAndView |
showForm(HttpServletRequest request,
HttpServletResponse response,
BindException errors)
Show first page as form view. |
protected ModelAndView |
showPage(HttpServletRequest request,
BindException errors,
int page)
Prepare the form model and view, including reference and error data, for the given page. |
protected void |
validatePage(Object command,
Errors errors,
int page)
Template method for custom validation logic for individual pages. |
protected void |
validatePage(Object command,
Errors errors,
int page,
boolean finish)
Template method for custom validation logic for individual pages. |
Methods inherited from class org.springframework.web.servlet.mvc.AbstractFormController |
---|
currentFormObject, formBackingObject, getCommand, getErrorsForNewForm, getFormSessionAttributeName, getFormSessionAttributeName, handleRequestInternal, isBindOnNewForm, isSessionForm, onBindOnNewForm, onBindOnNewForm, setBindOnNewForm, setSessionForm, showForm, showForm, showNewForm |
Methods inherited from class org.springframework.web.servlet.mvc.BaseCommandController |
---|
bindAndValidate, checkCommand, createBinder, createCommand, getBindingErrorProcessor, getCommandClass, getCommandName, getMessageCodesResolver, getPropertyEditorRegistrars, getValidator, getValidators, initApplicationContext, initBinder, isValidateOnBinding, onBind, onBind, setBindingErrorProcessor, setCommandClass, setCommandName, setMessageCodesResolver, setPropertyEditorRegistrar, setPropertyEditorRegistrars, setValidateOnBinding, setValidator, setValidators, suppressBinding, suppressValidation |
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController |
---|
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession |
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator |
---|
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, isContextRequired |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PARAM_FINISH
public static final String PARAM_CANCEL
public static final String PARAM_TARGET
public static final String PARAM_PAGE
setPageAttribute(java.lang.String)
,
Constant Field ValuesConstructor Detail |
---|
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).
Method Detail |
---|
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.
getViewName(javax.servlet.http.HttpServletRequest, Object, int)
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.
getPageCount(javax.servlet.http.HttpServletRequest, Object)
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(HttpServletRequest request, Object command, 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 validation
Exception
- in case of invalid state or argumentsBaseCommandController.bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object)
,
Errors
protected void onBindAndValidate(HttpServletRequest request, Object command, 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 page
Exception
- 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(HttpServletRequest request)
isFormSubmission
in class AbstractFormController
request
- current HTTP request
isFinishRequest(javax.servlet.http.HttpServletRequest)
,
isCancelRequest(javax.servlet.http.HttpServletRequest)
protected final Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception
referenceData
in class AbstractFormController
request
- current HTTP requestcommand
- form object with request parameters bound onto iterrors
- validation errors holder
null
if none
Exception
- in case of invalid state or argumentsModelAndView
protected Map referenceData(HttpServletRequest request, Object command, Errors errors, int page) throws Exception
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 page
null
if none
Exception
- in case of invalid state or argumentsreferenceData(HttpServletRequest, int)
,
ModelAndView
protected Map referenceData(HttpServletRequest request, int page) throws Exception
Default implementation returns null. Subclasses can override this to set reference data used in the view.
request
- current HTTP requestpage
- current wizard page
null
if none
Exception
- in case of invalid state or argumentsModelAndView
protected final ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception
showForm
in class AbstractFormController
request
- current HTTP requestresponse
- current HTTP responseerrors
- validation errors holder
null
if handled directly
Exception
- 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 ModelAndView showPage(HttpServletRequest request, BindException errors, int page) throws Exception
processFinish
implementations,
to show the corresponding page in case of validation errors.
request
- current HTTP requesterrors
- validation errors holderpage
- number of page to show
Exception
- in case of invalid state or argumentsprotected int getPageCount(HttpServletRequest request, Object command)
getPageCount()
.
Can be overridden to dynamically adapt the page count.
request
- current HTTP requestcommand
- the command object as returned by formBackingObject
getPageCount()
protected String getViewName(HttpServletRequest request, Object command, int page)
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 formBackingObject
getPageCount()
protected int getInitialPage(HttpServletRequest request, Object command)
getInitialPage(HttpServletRequest)
.
request
- current HTTP requestcommand
- the command object as returned by formBackingObject
getInitialPage(HttpServletRequest)
,
AbstractFormController.formBackingObject(javax.servlet.http.HttpServletRequest)
protected int getInitialPage(HttpServletRequest request)
request
- current HTTP request
protected String getPageSessionAttributeName(HttpServletRequest request)
Default implementation delegates to the getPageSessionAttributeName
version without arguments.
request
- current HTTP request
null
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 ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response) throws Exception
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 response
null
if handled directly
Exception
- in case of errorsAbstractFormController.showNewForm(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,
AbstractFormController.setBindOnNewForm(boolean)
protected final ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command, 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(HttpServletRequest request)
The default implementation checks the page session attribute. Subclasses can override this for customized page determination.
processFormSubmission(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
,
getPageSessionAttributeName(javax.servlet.http.HttpServletRequest)
protected boolean isFinishRequest(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 isFinish(HttpServletRequest request)
isFinishRequest
isFinishRequest(javax.servlet.http.HttpServletRequest)
protected boolean isCancelRequest(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 boolean isCancel(HttpServletRequest request)
isCancelRequest
isCancelRequest(javax.servlet.http.HttpServletRequest)
protected int getTargetPage(HttpServletRequest request, Object command, Errors errors, int currentPage)
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 specified
getTargetPage(HttpServletRequest, int)
protected int getTargetPage(HttpServletRequest request, int currentPage)
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 specified
PARAM_TARGET
protected void validatePage(Object command, Errors errors, int page, boolean finish)
validatePage(command, errors, 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 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, 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(HttpServletRequest request, Object command, 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-process
Exception
- in case of invalid state or argumentsprotected abstract ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command, 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
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 holder
Exception
- in case of invalid state or argumentsErrors
,
BindException.getModel()
,
showPage(javax.servlet.http.HttpServletRequest, org.springframework.validation.BindException, int)
protected ModelAndView processCancel(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception
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 errors
Exception
- in case of invalid state or argumentsErrors
,
BindException.getModel()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |