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: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 {/*from   w  w w . j a  v  a  2  s .co m*/
        Long id = domainService.save(obj);
        responseData(m, id);
    }
    return "admin/article/add-success";
}

From source file:com.sg.addressbookmvc.HomeControllerNoAjax.java

@RequestMapping(value = "/editAddressNoAjax", method = RequestMethod.POST)
public String editAddressNoAjax(@Valid @ModelAttribute("address") Address address, BindingResult result) {

    if (result.hasErrors()) {
        return "editAddressFormNoAjax";
    }/*from  w ww .j a  v a2s  . c  o  m*/

    dao.updateAddress(address);
    return "redirect:displayAddressBookNoAjax";
}

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

@RequestMapping(value = "addJobFinish", method = RequestMethod.POST)
public String addJobFinish(@Valid JobFinish jobFinish, BindingResult bindingResult, ModelMap map) {
    if (bindingResult.hasErrors()) {
        map.addAttribute("jobFinish", jobFinish);

        ArrayList<JobFinish> jobFinishs = jobFinishService.getJobFinish();
        map.addAttribute("jobFinishList", jobFinishs);

        ArrayList<JobCard> jobCards = jobCardService.getJobCards();
        map.addAttribute("jobCardList", jobCards);
        return "jobFinish";
    }/*from ww w.j a  va 2s . co  m*/
    jobFinishService.addJobFinish(jobFinish);

    ArrayList<JobFinish> jobFinishs = jobFinishService.getJobFinish();
    map.addAttribute("jobFinishList", jobFinishs);

    ArrayList<JobCard> jobCards = jobCardService.getJobCards();
    map.addAttribute("jobCardList", jobCards);

    map.addAttribute("jobFinish", new JobFinish());
    return "jobFinish";
}

From source file:sample.mvc.SignupController.java

@RequestMapping(method = RequestMethod.POST)
public String signup(@Valid User user, BindingResult result, RedirectAttributes redirect) {
    if (result.hasErrors()) {
        return "user/signup";
    }/*from   w  w w. j  ava2s  .  c o m*/
    user = userRepository.save(user);
    redirect.addFlashAttribute("globalMessage", "Successfully signed up");

    List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
    UserDetails userDetails = new org.springframework.security.core.userdetails.User(user.getEmail(),
            user.getPassword(), authorities);
    Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, user.getPassword(), authorities);
    SecurityContextHolder.getContext().setAuthentication(auth);
    return "redirect:/";
}

From source file:bibibi.controllers.CitationsController.java

@Transactional
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String postCitation(@Valid @ModelAttribute Citation citation, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return "addcitation";
    }//from w w  w.jav a  2  s  .  c o  m
    citationRepository.save(citation);
    return "redirect:/listcitations";
}

From source file:com.kazuki43zoo.jpetstore.ui.controller.CartController.java

@PostMapping(params = "update")
public String updateCart(@Validated CartUpdateForm form, BindingResult result, Model model) {
    if (result.hasErrors()) {
        model.addAttribute(new Messages().error("Input values are invalid. Please confirm error messages."));
        return viewCart();
    }//w w w  .  j a v  a2 s  . c  o  m
    form.getLines().forEach(x -> {
        if (x.getQuantity() > 0) {
            cart.setQuantityByItemId(x.getItemId(), x.getQuantity());
        } else {
            cart.removeItemById(x.getItemId());
        }
    });
    return "redirect:/cart";
}

From source file:com.studevs.controllers.SignUp.java

@RequestMapping(value = "signup", method = RequestMethod.POST)
public String doRequest2(Model model, HttpServletRequest request,
        @ModelAttribute(value = "userInformation") UserInformation userInformation,
        BindingResult bindingResult) {

    try {//w  w  w. j  a  va2  s .  c  o m

        if (bindingResult.hasErrors()) {

            return "index";
        } else {

            UserInformationProvider uip = (UserInformationProvider) new BeanProvider()
                    .getBean("userInformationProvider");

            if (uip.insertUserInformation(userInformation)) {

                request.getSession().setAttribute("userInformation", userInformation);
                return "home";
            } else {

                return "signup";
            }
        }
    } catch (Exception e) {

        return "index";
    }
}

From source file:com.tsg.dvdlibrarymvc.HomeControllerNoAjax.java

@RequestMapping(value = "/editDVDNoAjax", method = RequestMethod.POST)

public String EditDVDNoAjax(@Valid @ModelAttribute("dvd") DVD dvd, BindingResult result) {
    if (result.hasErrors()) {
        return "editDVDFormNoAjax";
    }//from  w ww.j a va 2s . c om

    dao.updateDVD(dvd);
    return "redirect:displayDVDListNoAjax";
}

From source file:com.work.petclinic.web.MessageController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) {
    if (result.hasErrors()) {
        return new ModelAndView("messages/messageForm", "formErrors", result.getAllErrors());
    }/*  w w w. ja va 2 s .  c  o m*/
    message = this.messageRepository.save(message);
    redirect.addFlashAttribute("statusMessage", "Successfully created a new message");
    return new ModelAndView("redirect:/messages/{message.id}", "message.id", message.getId());
}

From source file:technology.tikal.customers.service.ContactService.java

@RequestMapping(value = "/{contactId}", method = RequestMethod.POST)
public void updateContact(@PathVariable final Long customerId, @PathVariable final Long contactId,
        @Valid @RequestBody final Contact data, final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*from  w  w  w  .  ja  v a2 s.co m*/
    customersController.updateContact(customerId, contactId, data);
}