|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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.SimpleFormController
net.sf.valjax.AjaxSimpleFormController
public class AjaxSimpleFormController
SimpleFormController that configures the response, view and the model needed for Ajax.
Uses the same workflow as described in the parent implementation.
Any BindException
errors are processed and transformed
using getErrors
into a String that can be properly
digested in the Ajax response.
You will need to use the setValidatorView
to provide the default configuration as shown here:
<property name="validatorView"> <value>valjax-response</value> </property>
Field Summary | |
---|---|
protected static org.apache.commons.logging.Log |
log
|
Fields inherited from class org.springframework.web.servlet.mvc.BaseCommandController |
---|
DEFAULT_COMMAND_NAME |
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator |
---|
METHOD_GET, METHOD_HEAD, METHOD_POST |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
logger |
Constructor Summary | |
---|---|
AjaxSimpleFormController()
|
Method Summary | |
---|---|
protected String |
getErrors(BindException errors)
Formats the errors to be used in the AJax response. |
ModelAndView |
processAjaxSubmit(BindException errors)
Provide the ModelAndView to use for
the Ajax response. |
ModelAndView |
processFormSubmission(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors)
Proccess the form submission with any validation errors. |
void |
setValidatorResponse(String validatorResponse)
Token to use in the validatorView file
to allow Ajax to lookup the errors. |
void |
setValidatorView(String validatorView)
The view the Ajax response will use to lookup errors. |
Methods inherited from class org.springframework.web.servlet.mvc.SimpleFormController |
---|
doSubmitAction, getFormView, getSuccessView, isFormChangeRequest, isFormChangeRequest, onFormChange, onFormChange, onSubmit, onSubmit, onSubmit, referenceData, referenceData, setFormView, setSuccessView, showForm, showForm, suppressValidation |
Methods inherited from class org.springframework.web.servlet.mvc.AbstractFormController |
---|
currentFormObject, formBackingObject, getCommand, getErrorsForNewForm, getFormSessionAttributeName, getFormSessionAttributeName, handleInvalidSubmit, handleRequestInternal, isBindOnNewForm, isFormSubmission, isSessionForm, onBindOnNewForm, onBindOnNewForm, setBindOnNewForm, setSessionForm, showForm, showForm, showNewForm |
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, setServletContext |
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 |
---|
protected static final org.apache.commons.logging.Log log
Constructor Detail |
---|
public AjaxSimpleFormController()
Method Detail |
---|
public ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception
Check to see if the incoming request
is an Ajax call or not. If it is then processAjaxSubmit
,
otherwise we let processFormSubmission(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
do its job.
processFormSubmission
in class SimpleFormController
Exception
processAjaxSubmit(org.springframework.validation.BindException)
public ModelAndView processAjaxSubmit(BindException errors)
ModelAndView
to use for
the Ajax response.
Returns a new ModelAndView, setting the view as described
in setValidatorView
with the errors
from getErrors
loaded into the model with
setValidatorResponse
as the key
to the errors. This key is then used in the view to lookup the
error messages for the form.
errors
- Rejects from the validator
getErrors(org.springframework.validation.BindException)
,
setValidatorResponse
,
setValidatorView
protected String getErrors(BindException errors)
errors
to be used in the AJax response.
Each error is wrapped in '[ ]' with the name of the field and a list of all the errors for that field, using the '|' as a delimeter for each field error. The pairing in the first '[ ]' are the preset names used to identify the field and the error message(s).
Multiple fields with errors: [['id','msg'],['name','Required Field'],['number','Please enter a value between 10 and 20']] Multiple errors on the same field: [['id','msg'],['name','Required Field | Invalid Last Name']] Multiple errors on the same field and multiple fields with errors: [['id','msg'],['name','Required Field | Invalid Last Name'],['number','Please enter a value between 10 and 20']]
errors
- Validation errors to format.
public void setValidatorView(String validatorView)
This is required and needs to be set. The mandatory default is as follows.
<property name="validatorView"> <value>valjax-response</value> </property>
This corresponds to the valjax-response.jsp
file
that is used as the view when returning errors.
validatorView
- Name of the view when there are errors.public void setValidatorResponse(String validatorResponse)
validatorView
file
to allow Ajax to lookup the errors.
Default setting, if one is not set: validatorResponse
validatorResponse
- Name of the token to use to lookup errors.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |