List of usage examples for org.springframework.validation BindingResult hasErrors
boolean hasErrors();
From source file:technology.tikal.ventas.service.pedido.PedidoRaizService.java
@RequestMapping(produces = "application/json;charset=UTF-8", method = RequestMethod.GET) public Page<PedidoRaiz[]> consultar(@Valid @ModelAttribute final PaginationDataLong pagination, final BindingResult resultPagination, final HttpServletRequest httpRequest) { if (resultPagination.hasErrors()) { throw new NotValidException(resultPagination); }//from w w w . j av a 2 s . c om Page<PedidoRaiz[]> r = PaginationModelFactory.getPage(pedidoRaizController.consultar(pagination), "Pedido", httpRequest.getRequestURI(), null, pagination); return r; }
From source file:technology.tikal.ventas.service.pedimento.PedimentoBatchService.java
@RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)/* w ww .j a v a 2 s . c o m*/ public void crear(@PathVariable final Long pedidoId, @Valid @RequestBody final Pedimento request, final BindingResult result, final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) { if (result.hasErrors()) { throw new NotValidException(result); } Pedimento nuevo = pedimentoController.crear(pedidoId, request); httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId()); }
From source file:org.jtalks.common.web.dto.ValidationResults.java
/** * Constructor accepting binding result. It parses global and field errors. * * @param bindingResult BindingResult to be parsed. *///from w w w .j a v a2s . c o m public ValidationResults(BindingResult bindingResult) { this.success = !bindingResult.hasErrors(); populateFieldErrors(bindingResult); populateGlobalErrors(bindingResult); }
From source file:com.github.lynxdb.server.api.http.handlers.EpUser.java
@RequestMapping(value = "/{userLogin}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity updateUser(Authentication _authentication, @PathVariable("userLogin") String userLogin, @RequestBody @Valid UserUpdateRequest _ucr, BindingResult _bindingResult) { if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); });/*from ww w . j a v a 2 s.c o m*/ return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString()).response(); } User user = users.byLogin(userLogin); if (user == null) { return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, "User does not exist.", null).response(); } if (_ucr.password != null && !_ucr.password.isEmpty()) { user.setPassword(_ucr.password); } if (_ucr.rank != null) { user.setRank(_ucr.rank); } users.save(user); return ResponseEntity.ok(user); }
From source file:com.wiiyaya.consumer.web.main.controller.RoleController.java
@RequestMapping(value = MainURIResource.PATH_SYS_ROLE_ADD, method = { RequestMethod.POST }) @ResponseBody/*from www . j a va 2 s .c o m*/ public void add(@Validated @ModelAttribute(MainURIResource.MODEL_ROLE_DTO) RoleDto roleDto, BindingResult result) throws ValidateException, BusinessException { if (result.hasErrors()) { throw new ValidateException(result.getFieldError().getObjectName(), result.getFieldError().getField(), result.getFieldError().getDefaultMessage()); } roleService.saveRole(roleDto); }
From source file:com.wiiyaya.consumer.web.main.controller.RoleController.java
@RequestMapping(value = MainURIResource.PATH_SYS_ROLE_AMD, method = { RequestMethod.PUT }) @ResponseBody//from www . j a v a 2 s . co m public void amend(@Validated @ModelAttribute(MainURIResource.MODEL_ROLE_DTO) RoleDto roleDto, BindingResult result) throws ValidateException, BusinessException { if (result.hasErrors()) { throw new ValidateException(result.getFieldError().getObjectName(), result.getFieldError().getField(), result.getFieldError().getDefaultMessage()); } roleService.updateRole(roleDto); }
From source file:technology.tikal.gae.system.service.imp.SystemAccountServiceImp.java
@Override @RequestMapping(value = "/{user}", method = RequestMethod.POST) public void updateSystemAccount(@PathVariable String user, @Valid @RequestBody final SystemUser systemUser, final BindingResult result) { if (result.hasErrors()) { throw new NotValidException(result); }/*from w w w .j av a 2 s . co m*/ if (systemUser.getUsername() != null && user.compareTo(systemUser.getUsername()) != 0) { throw new MessageSourceResolvableException(new DefaultMessageSourceResolvable( new String[] { "NotSame.SystemAccountServiceImp.updateSystemAccount" }, new String[] { systemUser.getUsername(), user }, "Body username dont correspond to path username")); } else { SystemUser account = systemUserDao.consultar(user); account.update(systemUser); systemUserDao.guardar(account); } }
From source file:com.bangla.store.controller.CategoryController.java
@RequestMapping(value = "/edit/{id}", method = RequestMethod.POST) public String updateDetails(Model model, @Valid Category category, @PathVariable int id, BindingResult br, RedirectAttributes rAttributes) { if (br.hasErrors()) { model.addAttribute("category", category); return "category/edit"; } else {//from ww w. ja v a 2 s . c o m categoryService.update(category); rAttributes.addFlashAttribute("message", "Successfully updated item"); return "redirect:/category"; } }
From source file:com.local.ask.controller.spring.LoginController.java
@RequiresGuest @RequestMapping(value = "/login", method = RequestMethod.POST) public String submitLoginForm(@Valid LoginUser loginUser, BindingResult result, Model m, HttpServletRequest request) {//ww w . jav a 2 s . c om if (!result.hasErrors()) { try { UserTemp userTemp = new UserTemp(loginUser); Subject subject = SecurityUtils.getSubject(); subject.login(new UsernamePasswordToken(userTemp.getEmail(), userTemp.getPassword(), loginUser.getRememberMe())); Session session = subject.getSession(true); session.setAttribute("user", userTemp); session.setTimeout(24 * 3600000); m.addAttribute("message", "Successfully logged in person"); String referer = request.getHeader("referer"); if (referer != null && !referer.isEmpty()) { return REDIRECT + referer; } referer = (String) SecurityUtils.getSubject().getSession().getAttribute("fallback"); if (referer != null && !referer.isEmpty()) { return REDIRECT + referer; } } catch (AuthenticationException ex) { ex.printStackTrace(); m.addAttribute("message", "It seems your email is not registered."); } } return "login"; }
From source file:com.local.ask.controller.spring.PostController.java
@RequiresUser @RequestMapping(value = "/ask", method = RequestMethod.POST) public String loadAskForm(@Valid QuestionForm questionForm, BindingResult result, Model m) { if (result.hasErrors()) { return "ask_question"; } else {/*from www . j av a 2 s .c o m*/ dbHelper.addPost(questionForm); return REDIRECT_HOME; } }