Example usage for org.springframework.validation BindingResult getAllErrors

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

Introduction

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

Prototype

List<ObjectError> getAllErrors();

Source Link

Document

Get all errors, both global and field ones.

Usage

From source file:edu.swau.softball.web.DivisionController.java

@RequestMapping(value = "/new", method = RequestMethod.POST)
public String create(@ModelAttribute("division") Division division, BindingResult bindingResult,
        RedirectAttributes redirectAttributes, Model model) {
    validator.validate(division, bindingResult);
    if (bindingResult.hasErrors()) {
        log.warn("Could not create division. {}", bindingResult.getAllErrors());
        model.addAttribute("seasons", seasonService.all());
        return "/admin/division/new";
    }// w  ww.  j  a v  a  2 s  .c o m

    try {
        division = service.create(division);
        return "redirect:/admin/division/show/" + division.getId();
    } catch (Exception e) {
        log.error("Could not create division.", e);
        bindingResult.reject("Could not create division. {}", e.getMessage());
        model.addAttribute("seasons", seasonService.all());
        return "/admin/division/new";
    }
}

From source file:edu.swau.softball.web.DivisionController.java

@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String update(@ModelAttribute("division") Division division, BindingResult bindingResult,
        RedirectAttributes redirectAttributes, Model model) {
    validator.validate(division, bindingResult);
    if (bindingResult.hasErrors()) {
        log.warn("Could not update division. {}", bindingResult.getAllErrors());
        model.addAttribute("seasons", seasonService.all());
        return "/admin/division/edit";
    }//w w w  .j ava 2 s .c  om

    try {
        division = service.create(division);
        return "redirect:/admin/division/show/" + division.getId();
    } catch (Exception e) {
        log.error("Could not update division.", e);
        bindingResult.reject("Could not update division. {}", e.getMessage());
        model.addAttribute("seasons", seasonService.all());
        return "/admin/division/edit";
    }
}

From source file:edu.swau.softball.web.SeasonController.java

@RequestMapping(value = "/new", method = RequestMethod.POST)
public String create(@ModelAttribute("season") Season season, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    validator.validate(season, bindingResult);
    if (bindingResult.hasErrors()) {
        log.warn("Could not create season. {}", bindingResult.getAllErrors());
        return "/admin/season/new";
    }//from ww w.  j  a  v a2 s  .c o  m

    try {
        service.create(season);
        return "redirect:/admin/season/show/" + season.getId();
    } catch (Exception e) {
        log.error("Could not create season.", e);
        bindingResult.reject("Could not create season. {}", e.getMessage());
        return "/admin/season/new";
    }
}

From source file:edu.swau.softball.web.TeamController.java

@RequestMapping(value = "/new", method = RequestMethod.POST)
public String create(@ModelAttribute("team") Team team, BindingResult bindingResult,
        RedirectAttributes redirectAttributes, Model model) {
    validator.validate(team, bindingResult);
    if (bindingResult.hasErrors()) {
        log.warn("Could not create team. {}", bindingResult.getAllErrors());
        model.addAttribute("divisions", divisionService.all());
        return "/admin/team/new";
    }/*from   w ww.  j  a  v  a  2  s.c  om*/

    try {
        team = service.create(team);
        return "redirect:/admin/team/show/" + team.getId();
    } catch (Exception e) {
        log.error("Could not create team.", e);
        bindingResult.reject("Could not create team. {}", e.getMessage());
        model.addAttribute("divisions", divisionService.all());
        return "/admin/team/new";
    }
}

From source file:edu.swau.softball.web.TeamController.java

@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String update(@ModelAttribute("team") Team team, BindingResult bindingResult,
        RedirectAttributes redirectAttributes, Model model) {
    validator.validate(team, bindingResult);
    if (bindingResult.hasErrors()) {
        log.warn("Could not update team. {}", bindingResult.getAllErrors());
        model.addAttribute("divisions", divisionService.all());
        return "/admin/team/edit";
    }/* w ww. ja v  a2s.c  om*/

    try {
        team = service.create(team);
        return "redirect:/admin/team/show/" + team.getId();
    } catch (Exception e) {
        log.error("Could not update team.", e);
        bindingResult.reject("Could not update team. {}", e.getMessage());
        model.addAttribute("divisions", divisionService.all());
        return "/admin/team/edit";
    }
}

From source file:edu.zipcloud.cloudstreetmarket.core.util.ValidatorUtil.java

public static void raiseFirstError(BindingResult result) {
    if (result.hasFieldErrors()) {
        throw new IllegalArgumentException(result.getFieldError().getDefaultMessage());
    } else if (result.hasGlobalErrors()) {
        throw new IllegalArgumentException(result.getGlobalError().getDefaultMessage());
    } else if (result.hasErrors()) {
        throw new IllegalArgumentException(result.getAllErrors().get(0).getCode());
    }/*from w w  w .j av a2 s  .c o  m*/
}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.web.SubmissionReportController.java

@RequestMapping(value = SubmissionReportConstants.SUBMISSION_REPORT_URL, method = RequestMethod.POST)
public String handleSubmission(final ModelMap model, final Submission submission, final BindingResult result) {
    try {/*  w  w  w.j  a v  a2  s  . c  o m*/
        if (result.hasErrors()) {
            for (ObjectError error : (List<ObjectError>) result.getAllErrors()) {
                logger.info("Error: " + error.getCode() + " - " + error.getDefaultMessage());
            }
            model.addAttribute("response", buildManualJsonResponse(false, "Upload failed"));
        } else {
            final MultipartFile file = submission.getFileData();
            parseUploadedFile(file.getInputStream());
            model.addAttribute("response", buildManualJsonResponse(true, file.getOriginalFilename()));
        }
    } catch (IOException iox) {
        logger.info(iox.getMessage());
    }
    return SubmissionReportConstants.SUBMISSION_REPORT_VIEW;
}

From source file:io.ignitr.springboot.common.error.IgnitionErrorAttributes.java

/**
 * Adds field-level error messages to the error response.
 *
 * @param errorAttributes error attributes collection
 * @param requestAttributes request attributes collection
 *//*from  www .  j  a  v a 2  s. c  o m*/
private void addFieldErrors(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) {
    Throwable error = getError(requestAttributes);

    // Checking to see if the exception contains JSR-303 bean validation errors
    BindingResult result = extractBindingResult(error);
    if (result != null) {
        if (result.getErrorCount() > 0) {
            List<IgnitionFieldError> fieldErrors = new ArrayList<>(result.getErrorCount());

            for (ObjectError objError : result.getAllErrors()) {
                String field = ((FieldError) objError).getField();
                String message = objError.getDefaultMessage();

                fieldErrors.add(new IgnitionFieldError(field, message));
            }

            errorAttributes.put("fieldErrors", fieldErrors);
        }
    }

    // Checking to see if the exception is an ignition compatible exception and thus could
    // potentially contain field-level errors
    if (error instanceof IgnitionException) {
        if (((IgnitionException) error).hasFieldErrors()) {
            errorAttributes.put("fieldErrors", ((IgnitionException) error).getFieldErrors());
        }
    }
}

From source file:io.mandrel.spider.SpiderService.java

public Spider update(Spider spider) throws BindException {
    BindingResult errors = Validators.validate(spider);

    if (errors.hasErrors()) {
        errors.getAllErrors().stream().forEach(oe -> log.info(oe.toString()));
        throw new BindException(errors);
    }/*from   ww  w .  j  ava  2s  . c om*/

    updateTimeline(spider, SpiderEventType.SPIDER_UPDATED);

    return spiderRepository.update(spider);
}

From source file:io.mandrel.spider.SpiderService.java

public long fork(long id) throws BindException {
    Spider spider = get(id);// w  ww .  j  a v  a 2 s  . co  m
    spider.setId(0);
    spider.setName(generator.next());

    cleanDates(spider);

    BindingResult errors = Validators.validate(spider);

    if (errors.hasErrors()) {
        errors.getAllErrors().stream().forEach(oe -> log.info(oe.toString()));
        throw new BindException(errors);
    }

    spider.setStatus(SpiderStatuses.INITIATED);
    spider.setCreated(LocalDateTime.now());

    spider = spiderRepository.add(spider);

    return spider.getId();
}