List of usage examples for org.springframework.validation BindingResult hasErrors
boolean hasErrors();
From source file:org.parancoe.basicWebApp.ValidationTest.java
public void testPersonValidationInError() { Person person = new Person("", "Benfante", new Date()); BindingResult result = new BeanPropertyBindingResult(person, "person"); validator.validate(person, result);// ww w . j av a 2 s.c o m assertTrue(result.hasErrors()); assertSize(2, result.getAllErrors()); }
From source file:com.bangla.store.controller.CategoryController.java
@RequestMapping(value = "/add", method = RequestMethod.POST) public String postAdd(@ModelAttribute("category") @Valid Category category, BindingResult br, RedirectAttributes ra) {//from ww w .j ava 2 s.co m if (br.hasErrors()) { return "category/add"; } else { categoryService.create(category); ra.addFlashAttribute("message", "Successfully added item."); return "redirect:/category"; } }
From source file:edu.ijse.tcd.controller.CustomerController.java
@RequestMapping(value = "addCustomer", method = RequestMethod.POST) public String addCustomer(@Valid Customer customer, BindingResult bindingResult, ModelMap map) { if (bindingResult.hasErrors()) { ArrayList<Customer> customers = customerService.getCustomers(); map.addAttribute("customerList", customers); return "customer"; }//from w w w .j ava2s .c om customerService.addCustomer(customer); ArrayList<Customer> customers = customerService.getCustomers(); map.addAttribute("customerList", customers); ArrayList<Grade> grades = gradeService.getGrades(); map.addAttribute("grades", grades); map.addAttribute("customer", new Customer()); return "customer"; }
From source file:org.ng200.openolympus.controller.user.ChangePasswordController.java
@RequestMapping(method = RequestMethod.POST) public String changePassword(Model model, @Valid final PasswordChangeDto userDto, final BindingResult bindingResult, final Principal principal) { if (bindingResult.hasErrors()) { model.addAttribute("postUrl", "/user/changePassword"); model.addAttribute("hideOldPassword", false); return "user/changePassword"; }//from w ww .ja va2 s.c o m final User user = this.userRepository.findByUsername(principal.getName()); if (!this.passwordEncoder.matches(userDto.getExistingPassword(), user.getPassword())) { bindingResult.rejectValue("existingPassword", "", "user.changePassword.form.errors.existingPasswordDoesntMatch"); } if (!userDto.getPassword().equals(userDto.getPasswordConfirmation())) { bindingResult.rejectValue("passwordConfirmation", "", "user.changePassword.form.errors.passwordConfirmationDoesntMatch"); } if (bindingResult.hasErrors()) { model.addAttribute("hideOldPassword", false); model.addAttribute("postUrl", "/user/changePassword"); return "user/changePassword"; } user.setPassword(this.passwordEncoder.encode(userDto.getPassword())); this.userRepository.save(user); return "redirect:/user"; }
From source file:technology.tikal.ventas.service.system.SystemPedidoDataFix.java
@RequestMapping(produces = "application/json;charset=UTF-8", value = "/move/all/partida/{idDestino}", method = RequestMethod.GET) public Page<List<PartidaOfy>> moveAllPartida(@PathVariable final Long idOrigen, @PathVariable final Long idDestino, @Valid @ModelAttribute final PaginationDataLong pagination, final BindingResult resultPagination, final HttpServletRequest httpRequest) { if (resultPagination.hasErrors()) { throw new NotValidException(resultPagination); }//from www . j a v a 2 s. c o m PedidoOfy pedidoOrigen = pedidoDao.consultar(idOrigen); PedidoOfy pedidoDestino = pedidoDao.consultar(idDestino); List<PartidaOfy> partidas = partidaDao.consultarTodos(pedidoOrigen, null, pagination); for (PartidaOfy x : partidas) { if (x instanceof PartidaIntermediario) { PartidaIntermediario copia = new PartidaIntermediario(pedidoDestino); copia.update(x); partidaDao.guardar(pedidoDestino, copia); partidaDao.borrar(pedidoOrigen, x); } } Page<List<PartidaOfy>> r = PaginationModelFactory.getPage(partidas, "Partidas", httpRequest.getRequestURI(), null, pagination); return r; }
From source file:com.tsg.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 ww w . j a va2 s. com dao.updateAddress(address); return "redirect:displayAddressListNoAjax"; }
From source file:com.dub.skoolie.web.controller.admin.schedule.templates.AdminSchoolYearTemplateController.java
@RequestMapping(value = "/admin/schedule/templates/schoolyear", method = RequestMethod.POST) public ModelAndView addYearTemplate(@Valid SchoolYearTemplateBean schoolYearTemplateBean, BindingResult result, Model model) {/* w w w . j ava 2 s. c o m*/ //check if user is a district admin before they can add templates? if (result.hasErrors()) { model.addAttribute("schoolYearTemplateBean", schoolYearTemplateBean); model.addAttribute("schoolYearTemplateBeans", uiSchoolYearTemplateServiceImpl.getSchoolYearTemplates()); return new ModelAndView("admin/schedule/templates/schoolyear"); } uiSchoolYearTemplateServiceImpl.addSchoolYearTemplate(schoolYearTemplateBean); return new ModelAndView("redirect:/admin/schedule/templates/schoolyear"); }
From source file:com.example.securelogin.app.passwordchange.PasswordChangeController.java
@RequestMapping(method = RequestMethod.POST) public String change(@AuthenticationPrincipal LoggedInUser userDetails, @Validated PasswordChangeForm form, BindingResult bindingResult, Model model) { Account account = userDetails.getAccount(); if (bindingResult.hasErrors() || !account.getUsername().equals(form.getUsername())) { model.addAttribute(account);//from w w w .j a v a2 s .c om return "passwordchange/changeForm"; } passwordService.updatePassword(form.getUsername(), form.getNewPassword()); return "redirect:/password?complete"; }
From source file:com.gantzgulch.sharing.controller.SharedFileCommentController.java
@RequestMapping(method = RequestMethod.POST) public ModelAndView processForm(@Valid SharedFileCommentForm sharedFileCommentForm, BindingResult result, Map<String, Object> model) throws IOException { if (result.hasErrors()) { return new ModelAndView(".fileEdit", "sharedFile", sharedFileManager.findById(sharedFileCommentForm.getSharedFileId())); }/*from ww w. j a va2 s . c o m*/ sharedFileManager.addComment(sharedFileCommentForm, userManager.getCurrentUser()); return new ModelAndView("redirect:/secure/file.htm", "id", sharedFileCommentForm.getSharedFileId()); }
From source file:com.github.dbourdette.otto.web.controller.sources.BatchController.java
@RequestMapping(value = "/sources/{name}/events/batch", method = RequestMethod.POST) public String postEvent(@PathVariable String name, @Valid @ModelAttribute("form") BatchForm form, BindingResult bindingResult) throws JsonParseException, IOException { if (bindingResult.hasErrors()) { return "sources/batch_form"; }// w ww. j a va 2 s.c o m Source source = Source.findByName(name); for (int i = 0; i < form.getCount(); i++) { Event event = null; if (form.getValuesType() == BatchValuesType.JSON) { event = Event.fromJson(form.getValues()); } else { event = Event.fromKeyValues(form.getValues()); } event.setDateIfNoneDefined(form.getDateType().instanciateDate()); source.post(event); remoteEventsFacade.onEvent(name); } flashScope.message(form.getCount() + " events inserted for source " + name); return "redirect:/sources/{name}/events/batch"; }