List of usage examples for org.springframework.validation BindingResult hasErrors
boolean hasErrors();
From source file:org.sventon.web.ctrl.ConfigurationFormControllerTest.java
@Test public void onFormSubmitRedirectsToFormOnValidationError() { Application application = mock(Application.class); ConfigurationFormController controller = new ConfigurationFormController(application); BindingResult bindingResult = mock(BindingResult.class); when(bindingResult.hasErrors()).thenReturn(true); String formView = controller.onFormSubmit(new ConfigCommand(), bindingResult, mock(Model.class)); assertThat(formView, is(CONFIG_FORM_VIEW_NAME)); }
From source file:org.xinta.eazycode.components.shiro.web.controller.ManageUsersController.java
@RequestMapping(value = "/editUser", method = RequestMethod.POST) // @RequiresPermissions("user:edit") public String editUser(Model model, @RequestParam Long userId, @ModelAttribute EditUserVO command, BindingResult errors) { editUserValidator.validate(command, errors); if (errors.hasErrors()) { return "editUser"; }//from ww w .j ava2s . c o m User user = userService.getUser(userId); command.updateUser(user); userService.updateUser(user); return "redirect:/manageUsers.do"; }
From source file:uk.co.eggsylife.controller.StudentController.java
@RequestMapping(value = "/students/edit", method = RequestMethod.POST) public String saveStudentEdit(@ModelAttribute Student student, BindingResult errors, ModelMap modelMap) { studentValidator.validate(student, errors); if (errors.hasErrors()) { return STUDENT_EDIT_DIALOG_VIEW_KEY; } else {/* w ww . ja v a 2 s . c o m*/ students.add(student); modelMap.put("students", students); return STUDENTS_VIEW_KEY; } }
From source file:com.google.code.trapo.controller.ForumsController.java
@RequestMapping(value = { "/forum/save", "/forum/update" }, method = POST) public String save(@ModelAttribute("forum") @Valid Forum forum, BindingResult errors, Model model) { if (errors.hasErrors()) { model.addAttribute("message", error("Oops! There are some validation errors.")); return "forums/create"; }// w w w.j a v a 2s .co m if (exists(forum)) { forumRepository.update(forum); model.addAttribute("message", information("Forum was updated")); } else { forumRepository.add(forum.open()); model.addAttribute("message", information("New forum was created")); } model.addAttribute("forum", forum); return "forums/show"; }
From source file:oobbit.controllers.CommentController.java
@Secured({ "ROLE_MODERATOR", "ROLE_ADMINISTRATOR" }) @RequestMapping(value = "/{id}/edit", method = RequestMethod.POST) public String doEditComment(@PathVariable int id, @Valid Comment comment, BindingResult bindingResult, Model model) throws SQLException, NothingWasFoundException { if (bindingResult.hasErrors()) { model.addAttribute("roles", users.getCurrentUserRoles()); return "commentedit"; }/*from www .j ava2 s .c o m*/ comments.update(comment); Comment updated = comments.getOne(id); return "redirect:/view/" + updated.getLinkId(); }
From source file:technology.tikal.ventas.service.catalogo.CatalogoService.java
@RequestMapping(produces = "application/json;charset=UTF-8", method = RequestMethod.GET) public Page<Catalogo[]> consultar(@Valid @ModelAttribute final PaginationDataLong pagination, final BindingResult resultPagination, final HttpServletRequest httpRequest) { if (resultPagination.hasErrors()) { throw new NotValidException(resultPagination); }// w w w.ja v a 2s .c o m Page<Catalogo[]> r = PaginationModelFactory.getPage(catalogoController.consultar(pagination), "Pedido", httpRequest.getRequestURI(), null, pagination); return r; }
From source file:com.dub.skoolie.web.controller.system.SystemUserController.java
@RequestMapping(value = "/system/users", method = RequestMethod.POST) public ModelAndView addUser(@Valid UserBean userBean, BindingResult result, Model model) { if (result.hasErrors()) { model.addAttribute("userBean", userBean); model.addAttribute("users", uiUserServiceImpl.getUsers()); model.addAttribute("allUserTypes", uiUserServiceImpl.getUserTypes()); return new ModelAndView("system/users"); }//from w w w.j a v a2 s. c om uiUserServiceImpl.addUser(userBean); return new ModelAndView("redirect:/system/users/" + userBean.getUsername()); }
From source file:com.lixiaocong.rest.ArticleController.java
@RequestMapping(method = RequestMethod.POST) public Map<String, Object> post(@RequestBody @Valid ArticleForm article, BindingResult result) throws RestParamException { if (result.hasErrors()) throw new RestParamException(); DaoBasedUserDetails user = (DaoBasedUserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();/*from w w w . jav a 2s . c o m*/ articleService.create(user.getId(), article.getTitle(), article.getContent()); return ResponseMsgFactory.createSuccessResponse(); }
From source file:net.triptech.buildulator.web.UserController.java
@RequestMapping(method = RequestMethod.PUT) public String update(@Valid Person person, BindingResult bindingResult, Model uiModel, HttpServletRequest request) {/* w w w.j a v a 2 s. c o m*/ if (bindingResult.hasErrors()) { uiModel.addAttribute("person", person); FlashScope.appendMessage(getMessage("buildulator_object_validation", Person.class), request); return "user/update"; } Person user = getUser(request); if (user != null && StringUtils.equalsIgnoreCase(user.getOpenIdIdentifier(), person.getOpenIdIdentifier())) { // Only save the change if the logged in user is the same // Set some defaults from the current user person.setUserStatus(user.getUserStatus()); person.setUserRole(user.getUserRole()); uiModel.asMap().clear(); person.merge(); FlashScope.appendMessage(getMessage("buildulator_user_updated"), request); } return "redirect:/projects"; }
From source file:org.jblogcms.core.post.controller.EditPostController.java
/** * Submits form for adding new {@link Post} * * @param postForm the post with updated fields * @param result the {@code BindingResult} object * @param status the {@code SessionStatus} object * @param model the {@code Model} object * @return logical String-based view name *//*from ww w. jav a 2s . c o m*/ @PreAuthorize("hasRole('ROLE_USER')") @RequestMapping(value = "/admin/post/update/{postId}", method = RequestMethod.POST) public String editPostSubmitForm(@PathVariable("postId") long postId, @Valid @ModelAttribute("post") Post postForm, BindingResult result, SessionStatus status, Model model) { if (result.hasErrors()) { model.addAttribute("allBlogs", blogService.findBlogList(null)); return "admin/postEdit"; } else { Post post = editPost(postForm, result); if (post == null) { model.addAttribute("allBlogs", blogService.findBlogList(null)); return "admin/postEdit"; } status.setComplete(); return "redirect:/"; } }