Example usage for org.springframework.validation BindingResult hasErrors

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

Introduction

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

Prototype

boolean hasErrors();

Source Link

Document

Return if there were any errors.

Usage

From source file:gallery.web.validator.wallpaper.WallpaperInsertBindValidator.java

@Override
public BindingResult bindAndValidate(Object command, HttpServletRequest request) {
    BindingResult res = super.bindAndValidate(command, request);
    if (!res.hasErrors()) {
        //setting user
        Wallpaper p = (Wallpaper) command;
        p.setActive(Boolean.TRUE);
        p.setUser(security.Utils.getCurrentUser(request));
    }// ww w.j  a v a2s  .c  om
    return res;
}

From source file:com.library.bookarticlelibrary.controller.AuthorsController.java

@RequestMapping(value = { "authors/author/saveauthor",
        "authors/author/editauthor/saveauthor" }, method = RequestMethod.POST)
public ModelAndView saveAuthor(@Valid Author author, BindingResult authorResult) {
    if (authorResult.hasErrors()) {
        return new ModelAndView("addauthor");
    }/*w w  w. ja  v a 2s.co  m*/
    authorDao.saveOrUpdate(author);

    return new ModelAndView("redirect:/library/authors");
}

From source file:org.jboss.spring.quickstarts.kitchensink.kitchensink_spring.mvc.MemberController.java

@RequestMapping(method = RequestMethod.POST)
public String registerNewMember(@Valid @ModelAttribute("newMember") Member newMember, BindingResult result,
        Model model) {/*from ww  w. j a  va  2s  .  c  om*/
    if (!result.hasErrors()) {
        memberDao.register(newMember);
        return "redirect:/";
    } else {
        model.addAttribute("members", memberDao.findAllOrderedByName());
        return "index";
    }
}

From source file:com.dub.skoolie.web.controller.admin.school.AdminSchoolController.java

@Secured("ROLE_DISTRICT_ADMIN")
@RequestMapping(value = "/admin/schools", method = RequestMethod.POST)
public ModelAndView addSchool(@Valid SchoolBean schoolBean, BindingResult result, Model model) {
    if (result.hasErrors()) {
        model.addAttribute("schoolBean", schoolBean);
        model.addAttribute("schools", uiSchoolServiceImpl.getSchools());
        return new ModelAndView("admin/school/schools");
    }/*w  w  w .  j  a  va2s  . co  m*/
    uiSchoolServiceImpl.addSchool(schoolBean);
    return new ModelAndView("redirect:/admin/school/schools");
}

From source file:com.pw.ism.controllers.CommunicationController.java

@RequestMapping(value = "/addheartbeat", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
public ResponseEntity<String> addHeartbeat(@Valid @RequestBody Heartbeat hb, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        LOGGER.info("Bad request!");
        return new ResponseEntity<>("NOK!", HttpStatus.BAD_REQUEST);
    } else {//ww  w  .ja v  a  2 s. co m
        heartbeatRepository.addHeartbeat(hb, Instant.now());
        return new ResponseEntity<>("OK", HttpStatus.OK);
    }
}

From source file:edu.ijse.tcd.controller.SparePartController.java

@RequestMapping(value = "addSparePart", method = RequestMethod.POST)
public String addSparePart(@Valid SparePart sparePart, BindingResult bindingResult, ModelMap map) {
    if (bindingResult.hasErrors()) {
        ArrayList<SparePart> spareParts = sparePartService.getSparePart();

        map.addAttribute("SparePartList", spareParts);
        map.addAttribute("sparePart", sparePart);
        return "sparePart";
    }// w  ww.  ja v a  2s.  c  o m
    sparePartService.addSparePart(sparePart);
    ArrayList<SparePart> spareParts = sparePartService.getSparePart();

    map.addAttribute("SparePartList", spareParts);
    map.addAttribute("sparePart", new SparePart());
    return "sparePart";
}

From source file:com.github.carlomicieli.nerdmovies.controllers.AuthController.java

@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String createUser(@Valid MailUser user, BindingResult result) {
    if (result.hasErrors()) {
        return "auth/signup";
    }// w w w  .jav  a2  s.  c  o  m

    // set the default values for the user
    user.init();
    user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
    userService.createUser(user);

    // automatically sign in the new user
    securityService.authenticate(user);

    return "home/index";
}

From source file:io.curly.tagger.controller.TagController.java

@Loggable
@RequestMapping(method = RequestMethod.POST)
public DeferredResult<ResponseEntity<?>> save(@Valid @RequestBody Set<Tag> tags, BindingResult bindingResult) {
    if (bindingResult.hasErrors())
        return defer(Observable.just(new ResponseEntity<>(new ModelErrors(bindingResult), BAD_REQUEST)));
    writerCommand.save(tags);//from   w ww.j  av a  2 s .c  o  m
    return defer(Observable.just(new ResponseEntity<>(CREATED)));
}

From source file:com.gym.controller.GrupoController.java

@RequestMapping(value = "/nuevogrupo", method = RequestMethod.POST)
public String nuevoGrupo(@Valid GrupoMuscular grupo, BindingResult result) {

    if (result.hasErrors()) {
        return "nuevogrupo";
    }//from  w ww.j ava2s  .  c  o m

    grupoService.addGrupoMuscular(grupo);

    return "redirect:./gestgrupos";
}

From source file:com.pegawai.app.controller.PegawaiController.java

@RequestMapping(value = "form", method = RequestMethod.POST)
public String prosesForm(@ModelAttribute @Valid Pegawai k, BindingResult hasilValidasi) {
    if (hasilValidasi.hasErrors()) {
        return "/pegawai/form";
    }/*from w  w w  .jav a2 s .  c  om*/
    pegawaiService.save(k);
    return "redirect:list";
}