List of usage examples for org.springframework.validation BindingResult hasErrors
boolean hasErrors();
From source file:com.pw.ism.controllers.MessageController.java
@RequestMapping(value = "sendmail", method = RequestMethod.POST, headers = { "Content-type=application/json" }) public ResponseEntity<String> sendMail(@Valid @RequestBody MailMessage mail, BindingResult result) { if (result.hasErrors()) { for (ObjectError error : result.getAllErrors()) { LOGGER.info("not valid: " + error.toString()); }/* w w w. ja va 2 s. co m*/ return new ResponseEntity<>("NOK!", HttpStatus.BAD_REQUEST); } else { return new ResponseEntity<>("OK!", HttpStatus.OK); } }
From source file:technology.tikal.customers.service.CustomerService.java
@RequestMapping(value = "/{customerId}", method = RequestMethod.POST) public void updateCustomer(@PathVariable final Long customerId, @Valid @RequestBody final Customer data, final BindingResult result) { if (result.hasErrors()) { throw new NotValidException(result); }//from w w w. j av a 2 s . c om customersController.updateCustomer(customerId, data); }
From source file:xyz.autumnn.exam.springsocial.controller.signup.SignupController.java
@RequestMapping(value = "/signup", method = RequestMethod.POST) public String signup(@Valid SignupForm form, BindingResult formBinding, WebRequest request) { if (formBinding.hasErrors()) { return null; }/* w w w.j ava2 s . c o m*/ Account account = createAccount(form); if (account != null) { SignInUtils.signin(account.getUsername()); providerSignInUtils.doPostSignUp(account.getUsername(), request); return "redirect:/"; } return null; }
From source file:eu.agilejava.mvc.HelloController.java
@RequestMapping(value = "hello", method = POST) public ModelAndView formPost(@ModelAttribute("form") @Validated HelloBean form, BindingResult bindingResult) { if (bindingResult.hasErrors()) { Map<String, Object> errorModel = new HashMap<>(); ObjectError error = bindingResult.getAllErrors().iterator().next(); errorModel.put("property", ((FieldError) error).getField()); errorModel.put("value", ((FieldError) error).getRejectedValue()); errorModel.put("message", error.getDefaultMessage()); bindingResult.getAllErrors().stream().forEach(v -> { errorModel.put(((FieldError) v).getField(), v.getDefaultMessage()); });//from w ww . ja va 2 s .c o m ModelAndView mv = new ModelAndView("form", errorModel); return mv; } Map<String, Object> helloModel = new HashMap<>(); helloModel.put("name", form.getFirstName() + " " + form.getLastName()); ModelAndView mv = new ModelAndView("hello", helloModel); return mv; }
From source file:org.easit.core.controllers.facebook.FacebookVideosController.java
@RequestMapping(value = "/facebook/albums/videos/upload", method = RequestMethod.POST) public String uploadVideo(@Valid UploadItem uploadItem, BindingResult result) { if (result.hasErrors()) { return null; }//w ww. java 2 s . co m Resource video = getUploadResource(uploadItem.getFileData().getOriginalFilename(), uploadItem.getFileData()); facebook.mediaOperations().postVideo(video, uploadItem.getTitle(), uploadItem.getCaption()); return "redirect:/facebook/albums/videos"; }
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 {/* w ww. j a va 2 s. co m*/ Long id = service.save(obj); responseData(m, id); } return "admin/article/add-success"; }
From source file:technology.tikal.customers.service.ContactRelationshipService.java
@RequestMapping(value = "/{relationId}", method = RequestMethod.POST) public void updateRelation(@PathVariable final Long customerId, @PathVariable final Long contactId, @PathVariable final Long relationId, @Valid @RequestBody final ContactRelationship data, final BindingResult result) { if (result.hasErrors()) { throw new NotValidException(result); }/* www.j av a 2 s . c o m*/ customersController.updateRelation(customerId, contactId, relationId, data); }
From source file:technology.tikal.ventas.service.catalogo.CatalogoService.java
@RequestMapping(value = "/{idCatalogo}", method = RequestMethod.POST) public void actualizar(@PathVariable final Long idCatalogo, @Valid @RequestBody final Catalogo request, final BindingResult result) { if (result.hasErrors()) { throw new NotValidException(result); }//from w ww . j a va2 s .c o m if (request.getId() != null && Long.compare(request.getId(), idCatalogo) != 0) { throw new MessageSourceResolvableException( new DefaultMessageSourceResolvable(new String[] { "NoValidRequest.CatalogoService.actualizar" }, new String[] { request.getId() + "" }, "El id del path no corresponde al de la info mandada en el body")); } catalogoController.actualizar(idCatalogo, request); }
From source file:org.ucll.ip.spring_ip_project.controller.TankController.java
@RequestMapping(method = RequestMethod.POST, value = "/save") public String saveTank(@ModelAttribute("tank") Tank tank, BindingResult result, HttpServletRequest req) { if (result.hasErrors()) { String name = req.getParameter("player"); req.setAttribute("player", name); return "tankForm"; }/*from w w w . ja va 2s . c om*/ String name = req.getParameter("player"); system.addTank(tank); system.getPlayer(name).addTankToPlayer(tank); return "redirect:/player.htm"; }
From source file:pl.com.softproject.diabetyk.web.controller.UserController.java
@RequestMapping(value = "/register", method = RequestMethod.POST) public ModelAndView registerNewUser(@Valid UserDTO user, BindingResult bindingResult) { ModelAndView model = new ModelAndView(); if (bindingResult.hasErrors()) { model.setViewName("register"); return model; }/*from w w w . j a v a 2 s .c o m*/ userService.registerUser(user.getUserName(), user.getPassword(), user.getEmail()); model.setViewName("redirect:/home"); return model; }