|
|||||||||||
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
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 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 respective view names to setPages.
setPages(java.lang.String[])
,
validatePage(java.lang.Object, org.springframework.validation.Errors, int)
,
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 java.lang.String |
PARAM_CANCEL
Parameter triggering the cancel action. |
static java.lang.String |
PARAM_FINISH
Parameter triggering the finish action. |
static java.lang.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_POST |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
logger |
Constructor Summary | |
AbstractWizardFormController()
Create a new AbstractWizardFormController. |
Method Summary | |
protected int |
getCurrentPage(javax.servlet.http.HttpServletRequest request)
Return the current page number. |
protected int |
getInitialPage(javax.servlet.http.HttpServletRequest request)
Return the initial page of the wizard, i.e. |
protected int |
getInitialPage(javax.servlet.http.HttpServletRequest request,
java.lang.Object command)
Return the initial page of the wizard, i.e. |
protected java.lang.String |
getPageSessionAttributeName()
Return the name of the session attribute that holds the page object for this controller. |
protected int |
getTargetPage(javax.servlet.http.HttpServletRequest request,
int currentPage)
Return the target page specified in the request. |
protected int |
getTargetPage(javax.servlet.http.HttpServletRequest request,
java.lang.Object command,
Errors errors,
int currentPage)
Return the target page specified in the request. |
protected ModelAndView |
handleInvalidSubmit(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle an invalid submit request, e.g. |
protected boolean |
isCancel(javax.servlet.http.HttpServletRequest request)
Return if cancel action is specified in the request. |
protected boolean |
isFinish(javax.servlet.http.HttpServletRequest request)
Return if finish action is specified in the request. |
protected void |
onBindAndValidate(javax.servlet.http.HttpServletRequest request,
java.lang.Object command,
BindException errors)
Call page-specific onBindAndValidate method. |
protected void |
onBindAndValidate(javax.servlet.http.HttpServletRequest request,
java.lang.Object command,
BindException errors,
int page)
Callback for custom post-processing in terms of binding and validation. |
protected abstract ModelAndView |
processCancel(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Object command,
BindException errors)
Template method for processing the cancel action of this wizard. |
protected abstract ModelAndView |
processFinish(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Object command,
BindException errors)
Template method for processing the final action of this wizard. |
protected ModelAndView |
processFormSubmission(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Object command,
BindException errors)
Apply wizard workflow: finish, cancel, page change. |
protected java.util.Map |
referenceData(javax.servlet.http.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 java.util.Map |
referenceData(javax.servlet.http.HttpServletRequest request,
java.lang.Object command,
Errors errors)
Call page-specific referenceData method. |
protected java.util.Map |
referenceData(javax.servlet.http.HttpServletRequest request,
java.lang.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. |
void |
setAllowDirtyForward(boolean allowDirtyForward)
Set if "dirty forward" is allowed, i.e. |
void |
setPageAttribute(java.lang.String pageAttribute)
Set the name of the page attribute in the model, containing an Integer with the current page number. |
void |
setPages(java.lang.String[] pages)
Set the wizard pages, i.e. |
protected ModelAndView |
showForm(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
BindException errors)
Show first page as form view. |
protected ModelAndView |
showPage(javax.servlet.http.HttpServletRequest request,
BindException errors,
int page)
Prepare the form model and view, including reference and error data, for the given page. |
protected abstract void |
validatePage(java.lang.Object command,
Errors errors,
int page)
Template method for custom validation logic for individual pages. |
Methods inherited from class org.springframework.web.servlet.mvc.AbstractFormController |
formBackingObject, getCommand, getFormSessionAttributeName, handleRequestInternal, isBindOnNewForm, isFormSubmission, isSessionForm, setBindOnNewForm, setSessionForm, showForm, showForm, showNewForm |
Methods inherited from class org.springframework.web.servlet.mvc.BaseCommandController |
bindAndValidate, checkCommand, createBinder, createCommand, getCommandClass, getCommandName, getValidator, initBinder, isValidateOnBinding, onBind, setCommandClass, setCommandName, setValidateOnBinding, setValidator |
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController |
handleRequest, setSynchronizeOnSession |
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator |
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
getServletContext, getTempDir, getWebApplicationContext, requiredContextClass |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
getApplicationContext, getMessageSourceAccessor, initApplicationContext, setApplicationContext |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String PARAM_FINISH
public static final java.lang.String PARAM_CANCEL
public static final java.lang.String PARAM_TARGET
Constructor Detail |
public AbstractWizardFormController()
Method Detail |
public final void setPages(java.lang.String[] pages)
pages
- view names for the pagespublic final void setPageAttribute(java.lang.String pageAttribute)
pageAttribute
- name of the page attributepublic final void setAllowDirtyBack(boolean allowDirtyBack)
allowDirtyBack
- if "dirty back" is allowedpublic final void setAllowDirtyForward(boolean allowDirtyForward)
allowDirtyForward
- if "dirty forward" is allowedprotected final void onBindAndValidate(javax.servlet.http.HttpServletRequest request, java.lang.Object command, BindException errors) throws java.lang.Exception
onBindAndValidate
in class BaseCommandController
request
- current HTTP requestcommand
- command object, still allowing for further bindingerrors
- validation errors holder, allowing for additional
custom validation
java.lang.Exception
- in case of invalid state or argumentsBaseCommandController.bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object)
,
Errors
protected void onBindAndValidate(javax.servlet.http.HttpServletRequest request, java.lang.Object command, BindException errors, int page) throws java.lang.Exception
request
- current HTTP requestcommand
- bound commanderrors
- Errors instance for additional custom validationpage
- current wizard page
java.lang.Exception
- in case of invalid state or argumentsBaseCommandController.bindAndValidate(javax.servlet.http.HttpServletRequest, java.lang.Object)
,
Errors
protected final java.util.Map referenceData(javax.servlet.http.HttpServletRequest request, java.lang.Object command, Errors errors) throws java.lang.Exception
referenceData
in class AbstractFormController
request
- current HTTP requestcommand
- form object with request parameters bound onto iterrors
- validation errors holder
java.lang.Exception
- in case of invalid state or argumentsModelAndView
protected java.util.Map referenceData(javax.servlet.http.HttpServletRequest request, java.lang.Object command, Errors errors, int page) throws java.lang.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
java.lang.Exception
- in case of invalid state or argumentsreferenceData(HttpServletRequest, int)
,
ModelAndView
protected java.util.Map referenceData(javax.servlet.http.HttpServletRequest request, int page) throws java.lang.Exception
Default implementation returns null. Subclasses can override this to set reference data used in the view.
request
- current HTTP requestpage
- current wizard page
java.lang.Exception
- in case of invalid state or argumentsModelAndView
protected final ModelAndView showForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, BindException errors) throws java.lang.Exception
showForm
in class AbstractFormController
request
- current HTTP requestresponse
- current HTTP responseerrors
- validation errors holder
java.lang.Exception
- in case of invalid state or argumentsAbstractFormController.showForm(HttpServletRequest, BindException, String)
,
SimpleFormController.setFormView(java.lang.String)
protected final ModelAndView showPage(javax.servlet.http.HttpServletRequest request, BindException errors, int page) throws java.lang.Exception
request
- current HTTP requesterrors
- validation errors holderpage
- number of page to show
java.lang.Exception
- in case of invalid state or argumentsprotected int getInitialPage(javax.servlet.http.HttpServletRequest request, java.lang.Object command)
request
- current HTTP requestcommand
- the command object as returned by formBackingObject
getInitialPage(HttpServletRequest)
,
AbstractFormController.formBackingObject(javax.servlet.http.HttpServletRequest)
protected int getInitialPage(javax.servlet.http.HttpServletRequest request)
request
- current HTTP request
protected final java.lang.String getPageSessionAttributeName()
protected ModelAndView handleInvalidSubmit(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.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
java.lang.Exception
- in case of errorsAbstractFormController.showNewForm(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,
AbstractFormController.setBindOnNewForm(boolean)
protected final ModelAndView processFormSubmission(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, BindException errors) throws java.lang.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)
java.lang.Exception
- in case of errorsAbstractFormController.isFormSubmission(javax.servlet.http.HttpServletRequest)
,
AbstractFormController.showForm(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.springframework.validation.BindException)
,
Errors
protected int getCurrentPage(javax.servlet.http.HttpServletRequest request) throws java.lang.IllegalStateException
The default implementation checks the page session attribute. Subclasses can override this for customized target page determination.
java.lang.IllegalStateException
- if the page attribute isn't in the session
anymore, i.e. when called after processFormSubmission.getPageSessionAttributeName()
protected boolean isFinish(javax.servlet.http.HttpServletRequest request)
request
- current HTTP requestprotected boolean isCancel(javax.servlet.http.HttpServletRequest request)
request
- current HTTP requestprotected int getTargetPage(javax.servlet.http.HttpServletRequest request, java.lang.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(javax.servlet.http.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 abstract void validatePage(java.lang.Object command, Errors errors, int page)
command
- form object with the current wizard stateerrors
- validation errors holderpage
- number of page to showprotected abstract ModelAndView processFinish(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, BindException errors) throws java.lang.Exception
Can call errors.getModel() to populate the ModelAndView model with the command and the Errors instance, under the specified bean name.
request
- current HTTP requestresponse
- current HTTP responsecommand
- form object with the current wizard stateerrors
- validation errors holder
java.lang.Exception
- in case of invalid state or argumentsErrors
protected abstract ModelAndView processCancel(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, BindException errors) throws java.lang.Exception
Can call errors.getModel() to populate the ModelAndView model with the command and the Errors instance, under the specified bean name.
request
- current HTTP requestresponse
- current HTTP responsecommand
- form object with the current wizard stateerrors
- Errors instance containing errors
java.lang.Exception
- in case of invalid state or argumentsErrors
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |