本文整理匯總了Java中org.springframework.web.bind.ServletRequestDataBinder.getBindingResult方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletRequestDataBinder.getBindingResult方法的具體用法?Java ServletRequestDataBinder.getBindingResult怎麽用?Java ServletRequestDataBinder.getBindingResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.bind.ServletRequestDataBinder
的用法示例。
在下文中一共展示了ServletRequestDataBinder.getBindingResult方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getErrorsForNewForm
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Create a BindException instance for a new form.
* Called by {@link #showNewForm}.
* <p>Can be used directly when intending to show a new form but with
* special errors registered on it (for example, on invalid submit).
* Usually, the resulting BindException will be passed to
* {@link #showForm(HttpServletRequest, HttpServletResponse, BindException)},
* after registering the errors on it.
* @param request current HTTP request
* @return the BindException instance
* @throws Exception in case of an invalid new form object
* @see #showNewForm
* @see #showForm(HttpServletRequest, HttpServletResponse, BindException)
* @see #handleInvalidSubmit
*/
protected final BindException getErrorsForNewForm(HttpServletRequest request) throws Exception {
// Create form-backing object for new form.
Object command = formBackingObject(request);
if (command == null) {
throw new ServletException("Form object returned by formBackingObject() must not be null");
}
if (!checkCommand(command)) {
throw new ServletException("Form object returned by formBackingObject() must match commandClass");
}
// Bind without validation, to allow for prepopulating a form, and for
// convenient error evaluation in views (on both first attempt and resubmit).
ServletRequestDataBinder binder = createBinder(request, command);
BindException errors = new BindException(binder.getBindingResult());
if (isBindOnNewForm()) {
logger.debug("Binding to new form");
binder.bind(request);
onBindOnNewForm(request, command, errors);
}
// Return BindException object that resulted from binding.
return errors;
}
示例2: bindAndValidate
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Bind the parameters of the given request to the given command object.
* @param request current HTTP request
* @param command the command to bind onto
* @return the ServletRequestDataBinder instance for additional custom validation
* @throws Exception in case of invalid state or arguments
*/
protected final ServletRequestDataBinder bindAndValidate(HttpServletRequest request, Object command) throws Exception {
ServletRequestDataBinder binder = createBinder(request, command);
BindException errors = new BindException(binder.getBindingResult());
if (!suppressBinding(request)) {
binder.bind(request);
onBind(request, command, errors);
if (this.validators != null && isValidateOnBinding() && !suppressValidation(request, command, errors)) {
for (int i = 0; i < this.validators.length; i++) {
ValidationUtils.invokeValidator(this.validators[i], command, errors);
}
}
onBindAndValidate(request, command, errors);
}
return binder;
}
示例3: handleSubmit
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
@Override
public ModelAndView handleSubmit() {
HttpServletRequest request = getRequest();
T formBackingObject = formBackingObject(request);
ServletRequestDataBinder binder = bind(request, formBackingObject);
BindingResult bindingResult = binder.getBindingResult();
if (!suppressValidation(request, formBackingObject)) {
this.validateForm(formBackingObject, bindingResult);
}
processFormSubmission(request, formBackingObject, bindingResult);
if (bindingResult.hasErrors()) {
setSuccess(false);
}
return new ModelAndView(getViewIdentifier(), bindingResult.getModel());
}
示例4: handleRequestInternal
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Handles two cases: form submissions and showing a new form.
* Delegates the decision between the two to {@link #isFormSubmission},
* always treating requests without existing form session attribute
* as new form when using session form mode.
* @see #isFormSubmission
* @see #showNewForm
* @see #processFormSubmission
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Form submission or new form to show?
if (isFormSubmission(request)) {
// Fetch form object from HTTP session, bind, validate, process submission.
try {
Object command = getCommand(request);
ServletRequestDataBinder binder = bindAndValidate(request, command);
BindException errors = new BindException(binder.getBindingResult());
return processFormSubmission(request, response, command, errors);
}
catch (HttpSessionRequiredException ex) {
// Cannot submit a session form if no form object is in the session.
if (logger.isDebugEnabled()) {
logger.debug("Invalid submit detected: " + ex.getMessage());
}
return handleInvalidSubmit(request, response);
}
}
else {
// New form to show: render form view.
return showNewForm(request, response);
}
}
示例5: handleInvalidSubmit
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* 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).
* <p>The default implementation simply tries to resubmit the form with a new
* form object. This should also work if the user hit the back button, changed
* some form data, and resubmitted the form.
* <p>Note: To avoid duplicate submissions, you need to override this method.
* Either show some "invalid submit" message, or call {@link #showNewForm} for
* resetting the form (prepopulating it with the current values if "bindOnNewForm"
* is true). In this case, the form object in the session serves as transaction token.
* <pre>
* protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response) throws Exception {
* return showNewForm(request, response);
* }</pre>
* You can also show a new form but with special errors registered on it:
* <pre class="code">
* protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response) throws Exception {
* BindException errors = getErrorsForNewForm(request);
* errors.reject("duplicateFormSubmission", "Duplicate form submission");
* return showForm(request, response, errors);
* }</pre>
* @param request current HTTP request
* @param response current HTTP response
* @return a prepared view, or {@code null} if handled directly
* @throws Exception in case of errors
* @see #showNewForm
* @see #getErrorsForNewForm
* @see #showForm(HttpServletRequest, HttpServletResponse, BindException)
* @see #setBindOnNewForm
*/
protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response) throws Exception {
Object command = formBackingObject(request);
ServletRequestDataBinder binder = bindAndValidate(request, command);
BindException errors = new BindException(binder.getBindingResult());
return processFormSubmission(request, response, command, errors);
}