List of usage examples for org.springframework.validation BindingResult hasErrors
boolean hasErrors();
From source file:com.pkrete.locationservice.admin.controller.mvc.EditImageController.java
@RequestMapping(method = RequestMethod.POST) public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("image") Image image, BindingResult result) throws Exception { validator.validate(image, result);//from w w w . jav a 2 s .co m if (result.hasErrors()) { ModelMap model = new ModelMap(); model.put("external", image.getIsExternal()); model.put("imagesPath", image.getIsExternal() ? "" : Settings.getInstance().getImagesWebPath(getOwner(request).getCode())); return new ModelAndView("edit_image", model); } String imageId = request.getParameter("imageId"); image.setUpdater(getUser(request).getUsername()); if (!imagesService.update(image)) { throw new Exception("Updating image failed."); } return new ModelAndView("redirect:illustrations.htm?select_image=" + imageId); }
From source file:com.trenako.web.controllers.admin.AdminOptionsController.java
@RequestMapping(method = RequestMethod.POST) public String create(OptionForm form, BindingResult bindingResult, ModelMap model, RedirectAttributes redirectAtts) { if (bindingResult.hasErrors()) { model.addAttribute("newForm", form); return "option/new"; }/* w ww . ja v a 2 s .co m*/ Option option; try { option = form.buildOption(); service.save(option); OPTION_CREATED_MSG.appendToRedirect(redirectAtts); return "redirect:/admin/options"; } catch (IOException e) { log.error(e.toString()); } model.addAttribute("newForm", form); return "option/new"; }
From source file:cz.PA165.vozovyPark.controller.VehicleController.java
@RequestMapping(value = "/vehicle/new", method = RequestMethod.POST) public String addVehicle(@Valid @ModelAttribute("vehicle") VehicleDTO vehicle, BindingResult result) { // @Valid validates model after binding user input to it if (result.hasErrors()) { return "/vehicle/vehicleForm"; }//from w w w. j av a 2s . c om vehicleService.createVehicle(vehicle); return "redirect:/vehicle/allVehicles"; }
From source file:org.smigo.comment.CommentController.java
@PreAuthorize("isAuthenticated()") @RequestMapping(value = "/rest/comment", produces = "application/json", method = RequestMethod.PUT) @ResponseBody//from ww w .j av a 2 s . c o m public Object updateComment(@Valid @RequestBody Comment comment, BindingResult result, @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) { if (result.hasErrors()) { response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); } commentHandler.updateComment(comment, user); return Collections.emptyList(); }
From source file:org.wallride.web.controller.admin.user.UserInvitationCreateController.java
@RequestMapping(method = RequestMethod.POST) public String save(@PathVariable String language, @Valid @ModelAttribute("form") UserInvitationCreateForm form, BindingResult result, String query, AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) throws MessagingException { if (result.hasErrors()) { return "user/invitation/index"; }// w w w .jav a 2 s . c o m List<UserInvitation> invitations = userService.inviteUsers(form.buildUserInvitationCreateRequest(), result, authorizedUser); redirectAttributes.addFlashAttribute("savedInvitations", invitations); redirectAttributes.addAttribute("query", query); return "redirect:/_admin/{language}/users/invitations/index"; }
From source file:com.nicodewet.web.SubscribeController.java
@RequestMapping(value = "/subscribeth", method = RequestMethod.POST) public String subscribe(@Valid final Subscription subscription, final BindingResult bindingResult, final ModelMap model, RedirectAttributes redirectAttributes) { if (bindingResult.hasErrors()) { return "subscribeth"; } else {//from w w w. ja v a2 s . com logger.info("JUST ADDED SUBSCRIPTION: " + subscription); model.clear(); redirectAttributes.addFlashAttribute("subscribed", "success"); return "redirect:/subscribeth"; } }
From source file:elekto.results.ResultsController.java
/** * Upload the candidats model excel file. * // w ww . j a v a 2 s . c o m * @param resultsInputsForm * @param errors * * @return the redirect view. * * @throws IOException * if unable to read the file. */ @RequestMapping(value = "/calculate", method = POST) public ModelAndView calculateResults( @ModelAttribute(MODEL_ATTRIBUTE_RESULTS_INPUTS) final ResultsInputsForm resultsInputsForm, final BindingResult errors) throws IOException { new ResultInputsValidator().validate(resultsInputsForm, errors); if (errors.hasErrors()) { LOGGER.error("errors: {}", errors); return new ModelAndView("redirect:calculate"); } resultsInputsForm.cacheElectionsModelData(); return new ModelAndView("redirect:calculate"); }
From source file:org.openmrs.module.pharm.web.controller.PharmFormController.java
/** * All the parameters are optional based on the necessity * * @param httpSession//from w w w .j ava 2 s . c om * @param anyRequestObject * @param errors * @return */ @RequestMapping(method = RequestMethod.POST) public String onSubmit(HttpSession httpSession, @ModelAttribute("anyRequestObject") Object anyRequestObject, BindingResult errors) { System.out.println("POST method***************"); if (errors.hasErrors()) { // return error view } return SUCCESS_FORM_VIEW; }
From source file:technology.tikal.ventas.service.almacen.SalidaService.java
@RequestMapping(produces = "application/json;charset=UTF-8", method = RequestMethod.GET) public Page<Salida[]> consultar(@PathVariable final Long pedidoId, @Valid @ModelAttribute final RegistroAlmacenFilter filter, final BindingResult resultFilter, @Valid @ModelAttribute final PaginationDataLong pagination, final BindingResult resultPagination, final HttpServletRequest httpRequest) { if (resultPagination.hasErrors()) { throw new NotValidException(resultPagination); }/*from w w w.ja va 2 s . co m*/ if (resultFilter.hasErrors()) { throw new NotValidException(resultFilter); } Page<Salida[]> r = PaginationModelFactory.getPage(salidaController.consultar(pedidoId, filter, pagination), "Entrada", httpRequest.getRequestURI(), null, pagination); return r; }