Example usage for org.springframework.validation BindingResult getErrorCount

List of usage examples for org.springframework.validation BindingResult getErrorCount

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult getErrorCount.

Prototype

int getErrorCount();

Source Link

Document

Return the total number of errors.

Usage

From source file:org.springframework.web.servlet.mvc.generic.GenericFormController.java

/**
 * This implementation calls {@link #showForm} in case of errors,
 * and delegates to  {@link #onSubmit}'s variant else.
 * <p>This can only be overridden to check for an action that should be executed
 * without respect to binding errors, like a cancel action. To just handle successful
 * submissions without binding errors, override the {@link #onSubmit} method.
 * @see #showForm//from   w ww  .  j  av  a  2  s. c  om
 * @see #onSubmit
 */
protected ModelAndView processFormSubmission(HttpServletRequest request, T formObject,
        BindingResult bindingResult) throws Exception {

    if (bindingResult.hasErrors()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Data binding errors: " + bindingResult.getErrorCount());
        }
        return showForm(request, bindingResult);
    } else {
        logger.debug("No errors -> processing submit");
        ModelAndView mav = onSubmit(request, formObject, bindingResult);
        if (mav != null) {
            return mav;
        } else {
            return showForm(request, bindingResult);
        }
    }
}