Example usage for org.springframework.validation BindingResult getFieldErrors

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

Introduction

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

Prototype

List<FieldError> getFieldErrors();

Source Link

Document

Get all errors associated with a field.

Usage

From source file:com.tsg.cms.validation.RESTValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)// ww w . jav a  2s  .c o  m
@ResponseBody
public ValidationErrorContainer processMethodArgumentNotValidException(MethodArgumentNotValidException e) {

    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    ValidationErrorContainer errors = new ValidationErrorContainer();

    for (FieldError currentError : fieldErrors) {

        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());

    }

    return errors;

}

From source file:net.noday.d4c.web.SubdomainController.java

@RequestMapping(method = RequestMethod.POST)
public String save(@Valid Subdomain obj, BindingResult result, Model m) {
    if (result.hasErrors()) {
        m.addAttribute(result.getFieldErrors());
    } else {/*from  ww w .  j  av  a  2s.c  om*/
        Long id = subdomainService.createSubdomain(obj);
        m.addAttribute("subdomain", null);
        responseData(m, id);
    }
    return null;
}

From source file:org.openlmis.fulfillment.web.BaseController.java

Map<String, String> getErrors(BindingResult bindingResult) {
    return bindingResult.getFieldErrors().stream()
            .collect(Collectors.toMap(FieldError::getField, FieldError::getCode));
}

From source file:com.silentwu.schedule.dto.ResponseDto.java

@SuppressWarnings("unchecked")
public <T extends ResponseDto> T appendErrors(BindingResult result) {
    final List<FieldError> fieldErrors = result.getFieldErrors();
    for (FieldError fieldError : fieldErrors) {
        final String defaultMessage = fieldError.getDefaultMessage();
        this.message += defaultMessage + ";";
    }//from ww  w.  j  a  va2  s.c o  m
    this.successful = false;
    return (T) this;
}

From source file:de.knightsoftnet.validators.server.controller.RestErrorHandler.java

/**
 * handle validation errors./*from   w  ww.j  a v  a  2 s  .c  om*/
 *
 * @param pexception exception which is thrown when data is invalid.
 * @return ValidationResultData with validation errors
 */
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ValidationResultInterface processValidationError(final MethodArgumentNotValidException pexception) {
    final BindingResult result = pexception.getBindingResult();
    final List<FieldError> fieldErrors = result.getFieldErrors();

    return this.processFieldErrors(fieldErrors);
}

From source file:net.noday.d4c.web.DomainController.java

@RequestMapping(value = "share", method = RequestMethod.POST)
public String share(@Valid Domain obj, BindingResult result, Model m) {
    try {//from w  ww.  j a  v a 2  s  . com
        if (result.hasErrors()) {
            m.addAttribute(result.getFieldErrors());
        } else {
            Long id = domainService.createDomain(obj);
            m.addAttribute("domain", null);
            responseData(m, id);
            return "redirect:/login";
        }
    } catch (Exception e) {
        responseMsg(m, false, e.getMessage());
    }
    return "share";
}

From source file:net.noday.core.web.BaseController.java

protected void responseValidError(Model m, BindingResult r) {
    m.addAttribute(r.getFieldErrors());
}

From source file:net.noday.d4c.web.SubdomainManager.java

@Override
public String save(@Valid Subdomain obj, BindingResult result, Model m) {
    if (result.hasErrors()) {
        m.addAttribute(result.getFieldErrors());
    } else {/*w w w .  ja v a 2s. c  om*/
        Long id = domainService.save(obj);
        responseData(m, id);
    }
    return "admin/article/add-success";
}

From source file:net.noday.d4c.web.DnsrecordManager.java

@Override
public String save(@Valid DnsRecord obj, BindingResult result, Model m) {
    if (result.hasErrors()) {
        m.addAttribute(result.getFieldErrors());
    } else {/*from  w  w w.j  a va 2 s .  c  om*/
        Long id = service.save(obj);
        responseData(m, id);
    }
    return "admin/article/add-success";
}

From source file:com.springdemob.controllers.MainController.java

@RequestMapping(value = "/loginsubmit", method = RequestMethod.POST)
@ResponseBody//from ww  w . j av  a 2s  .c  o m
public String LoginSubmit(@ModelAttribute("loginForm") @Validated LoginForm loginForm, BindingResult result,
        Model model) {

    if (result.hasErrors()) {

        return "Form has following Errors: " + result.getFieldErrors().get(0).toString();
    }
    logger.info("user name:" + loginForm.getUsername());
    logger.info("pass:" + loginForm.getPassword());
    String rval = loginService.Authenticate(loginForm);
    return rval;
}