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:com.bangla.store.controller.UserController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String SaveUser(@ModelAttribute("users") @Valid Users users, BindingResult br, RedirectAttributes ra) {
    if (br.hasErrors()) {
        return "users/add";
    } else {//from   w  ww  .  ja  v  a  2s  . c o m
        userService.create(users);
        ra.addFlashAttribute("message", "Saved successfully.");
        return "redirect:/user";
    }
}

From source file:com.mistar.deamon.core.controller.WelcomeController.java

@RequestMapping(value = "/validate", method = RequestMethod.POST)
public String checkPersonInfo(Model model, @Valid PersonForm personForm, BindingResult bindingResult) {

    if (bindingResult.hasErrors()) {
        model.addAttribute("personForm", personForm);
        return "form";
    }//www. j  a va2s  . c  o m

    return "redirect:/results";
}

From source file:funnycats.CatController.java

@RequestMapping(method = RequestMethod.POST)
public String rate(FunnyCat cat, BindingResult result) {
    if (result.hasErrors()) {
        return "cats/main";
    }/*  ww w .  ja v  a2  s  . c om*/
    // TBD: access as static variable
    this.cats.put(cat.getId(), cat);
    return "redirect:/cats/view/" + cat.getId();
}

From source file:mvc.controller.TarefaController.java

@RequestMapping("/adicionaTarefa")
public String adiciona(@Valid Tarefa tarefa, BindingResult result) {

    if (result.hasErrors()) {
        return "tarefa/formularioAdicionaTarefa";
    }/*  w  ww .  j ava  2 s . co m*/

    dao.adicionaTarefa(tarefa);
    return "tarefa/tarefa-adicionada";
}

From source file:mvc.SmsNoticeTimeController.java

@RequestMapping("/add")
public String add(Map<String, Object> model, @ModelAttribute("obj") SmsNoticeTime obj,
        BindingResult bindingRes) {
    if (!bindingRes.hasErrors()) {
        ServiceResult res = service.save(obj);
        addErrorsToModel(model, res);//from  w ww .java  2s  . c o  m
        if (!res.hasErrors()) {
            return "redirect:/SmsNoticeTime/search";
        }
    }
    return "SmsNoticeTime_search";
}

From source file:thymeleafsandbox.springjsp.web.controller.jsp.JspForm.java

@RequestMapping("/jsp/form")
public String showForm(@ModelAttribute("user") final User user, final BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        System.out.println("IN ERROR: " + user);
        return "jsp/form";
    }//www.ja  v a2 s  .c o  m
    System.out.println(user);
    return "jsp/form";
}

From source file:thymeleafsandbox.springjsp.web.controller.thymeleaf.ThymeleafForm.java

@RequestMapping("/thymeleaf/form")
public String showForm(final User user, final BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        System.out.println("IN ERROR: " + user);
        return "thymeleaf/form";
    }/*from  w ww  .  j a  v a  2  s.co m*/
    System.out.println(user);
    return "thymeleaf/form";
}

From source file:com.example.session.app.cart.CartController.java

@RequestMapping(method = RequestMethod.POST)
String removeFromCart(@Validated CartForm cartForm, BindingResult bindingResult, Model model) {
    if (bindingResult.hasErrors()) {
        ResultMessages messages = ResultMessages.error().add("e.st.ca.5001");
        model.addAttribute(messages);/* w  w  w . j a v a  2 s . co m*/
        return viewCart(model);
    }
    cart.remove(cartForm.getRemovedItemsIds()); // (2)
    return "redirect:/cart";
}

From source file:org.fede.calculator.web.controller.LaPlataAddressCalculator.java

@RequestMapping(value = "/address", method = RequestMethod.POST)
public LaPlataAddressDTO computeAddress(@RequestBody @Valid LaPlataAddressDTO address, BindingResult result) {

    if (result.hasErrors()) {
        return new LaPlataAddressDTO(result.getFieldError("originalText").getDefaultMessage(),
                address.getOriginalText());
    }//from   w  w  w.  j  ava2 s. co m
    LaPlataAddressDTO answer = this.addressService.getAddress(address);
    if (!answer.isValid()) {
        return new LaPlataAddressDTO("La direccin ingresada no es vlida.", address.getOriginalText());
    }
    return answer;
}

From source file:org.jboss.spring3_2.example.ControllerAdvice.mvc.MemberController.java

@RequestMapping(method = RequestMethod.POST)
public String registerNewMember(@Valid @ModelAttribute("newMember") Member newMember, BindingResult result,
        Model model) {/*  www .j  a  v  a  2  s  . co m*/
    if (!result.hasErrors()) {
        memberDao.register(newMember);
        return "redirect:/";
    } else {
        return "index";
    }
}