List of usage examples for org.springframework.validation BindingResult rejectValue
void rejectValue(@Nullable String field, String errorCode);
From source file:org.wallride.web.controller.guest.user.SignupController.java
@RequestMapping(method = RequestMethod.POST) public String signup(@Valid @ModelAttribute("form") SignupForm form, BindingResult errors, RedirectAttributes redirectAttributes) { redirectAttributes.addFlashAttribute(FORM_MODEL_KEY, form); redirectAttributes.addFlashAttribute(ERRORS_MODEL_KEY, errors); if (errors.hasErrors()) { return "redirect:/signup?step.edit"; }/*from w ww .j ava2 s.co m*/ try { signupService.signup(form.toSignupRequest(), User.Role.VIEWER); } catch (DuplicateLoginIdException e) { errors.rejectValue("loginId", "NotDuplicate"); return "redirect:/signup?step.edit"; } catch (DuplicateEmailException e) { errors.rejectValue("email", "NotDuplicate"); return "redirect:/signup?step.edit"; } redirectAttributes.getFlashAttributes().clear(); return "redirect:/"; }
From source file:org.wallride.web.controller.admin.tag.TagRestController.java
@RequestMapping(value = "/{language}/tags/merge", method = RequestMethod.POST) public @ResponseBody DomainObjectSavedModel merge(@Valid TagMergeForm form, BindingResult errors, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { if (errors.hasErrors()) { throw new BindException(errors); }/*from w w w . j av a2s .com*/ Tag mergedTag; try { mergedTag = tagService.mergeTags(form.toTagMergeRequest(), authorizedUser); } catch (DuplicateNameException e) { errors.rejectValue("name", "NotDuplicate"); throw new BindException(errors); } FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("mergedTag", mergedTag); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectSavedModel<>(mergedTag); }
From source file:org.wallride.web.controller.admin.tag.TagRestController.java
@RequestMapping(value = "/{language}/tags", method = RequestMethod.POST) public @ResponseBody DomainObjectSavedModel save(@Valid TagCreateForm form, BindingResult errors, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { if (errors.hasErrors()) { throw new BindException(errors); }//from w ww. ja v a 2 s . c o m Tag savedTag; try { savedTag = tagService.createTag(form.buildTagCreateRequest(), authorizedUser); } catch (DuplicateNameException e) { errors.rejectValue("name", "NotDuplicate"); throw new BindException(errors); } FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("savedTag", savedTag); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectSavedModel<>(savedTag); }
From source file:org.wallride.web.controller.admin.customfield.CustomFieldEditController.java
@RequestMapping(method = RequestMethod.POST) public String update(@PathVariable String language, @Validated @ModelAttribute("form") CustomFieldEditForm form, BindingResult errors, String query, AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) { if (errors.hasErrors()) { return "customField/edit"; }/* w ww.j a v a 2s. c om*/ CustomField customField = null; try { customField = customFieldService.updateCustomField(form.buildCustomFieldUpdateRequest(), authorizedUser); } catch (EmptyCodeException e) { errors.rejectValue("code", "NotNull"); } catch (DuplicateCodeException e) { errors.rejectValue("code", "NotDuplicate"); } if (errors.hasErrors()) { logger.debug("Errors: {}", errors); return "customfield/edit"; } redirectAttributes.addFlashAttribute("savedCustomField", customField); redirectAttributes.addAttribute("language", language); redirectAttributes.addAttribute("id", customField.getId()); return "redirect:/_admin/{language}/customfields/index"; }
From source file:org.wallride.web.controller.admin.customfield.CustomFieldCreateController.java
@RequestMapping(method = RequestMethod.POST) public String save(@PathVariable String language, @Validated @ModelAttribute("form") CustomFieldCreateForm form, BindingResult errors, String query, AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) throws BindException { if (errors.hasErrors()) { return "customfield/create"; }//from www. j av a 2 s. c o m CustomField customfield = null; try { customfield = customfieldService.createCustomField(form.buildCustomFieldCreateRequest(), authorizedUser); } catch (EmptyCodeException e) { errors.rejectValue("code", "NotNull"); } catch (DuplicateCodeException e) { errors.rejectValue("code", "NotDuplicate"); } if (errors.hasErrors()) { logger.debug("Errors: {}", errors); return "customfield/create"; } redirectAttributes.addFlashAttribute("savedCustomField", customfield); redirectAttributes.addAttribute("language", language); redirectAttributes.addAttribute("id", customfield.getId()); return "redirect:/_admin/{language}/customfields/index"; }
From source file:org.wallride.web.controller.admin.page.PageCreateController.java
@RequestMapping(method = RequestMethod.POST, params = "publish") public String saveAsPublished(@PathVariable String language, @Validated({ Default.class, PageCreateForm.GroupPublish.class }) @ModelAttribute("form") PageCreateForm form, BindingResult errors, String query, AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) { if (errors.hasErrors()) { return "page/create"; }//from ww w . ja v a 2s . co m Page page = null; try { page = pageService.createPage(form.buildPageCreateRequest(), Post.Status.PUBLISHED, authorizedUser); } catch (EmptyCodeException e) { errors.rejectValue("code", "NotNull"); } catch (DuplicateCodeException e) { errors.rejectValue("code", "NotDuplicate"); } if (errors.hasErrors()) { logger.debug("Errors: {}", errors); return "page/create"; } redirectAttributes.addFlashAttribute("savedPage", page); redirectAttributes.addAttribute("language", language); redirectAttributes.addAttribute("id", page.getId()); redirectAttributes.addAttribute("query", query); return "redirect:/_admin/{language}/pages/describe"; }
From source file:de.whs.poodle.controllers.instructor.ManageCourseController.java
@RequestMapping(method = RequestMethod.POST) @PreAuthorize("@instructorSecurity.hasAccessToCourse(authentication.name, #courseId)") public String edit(@PathVariable int courseId, @Valid Course course, BindingResult bindingResult, RedirectAttributes redirectAttributes, Model model) { if (bindingResult.hasErrors()) return "instructor/manageCourse"; try {/*w ww . j a va2 s.c om*/ course.setId(courseId); courseRepo.edit(course); redirectAttributes.addFlashAttribute("okMessageCode", "settingsSaved"); return "redirect:/instructor/courses/{courseId}"; } catch (RepositoryException e) { bindingResult.rejectValue("name", "courseWithThisNameAlreadyExists"); return "instructor/manageCourse"; } }
From source file:org.wallride.web.controller.admin.tag.TagRestController.java
@RequestMapping(value = "/{language}/tags/{id}", method = RequestMethod.POST) public @ResponseBody DomainObjectUpdatedModel update(@Valid TagEditForm form, BindingResult errors, @PathVariable long id, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { form.setId(id);/*from w w w . j a v a2 s . c om*/ if (errors.hasErrors()) { throw new BindException(errors); } Tag savedTag; try { savedTag = tagService.updateTag(form.buildTagUpdateRequest(), authorizedUser); } catch (DuplicateNameException e) { errors.rejectValue("name", "NotDuplicate"); throw new BindException(errors); } FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("savedTag", savedTag); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectUpdatedModel<>(savedTag); }
From source file:de.whs.poodle.controllers.instructor.NewCourseController.java
@RequestMapping(method = RequestMethod.POST) public String create(@ModelAttribute Instructor instructor, @Valid NewCourseForm form, BindingResult bindingResult, RedirectAttributes redirectAttributes, Model model) { if (bindingResult.hasErrors()) return "instructor/newCourse"; try {/*from w w w .j av a 2s . co m*/ Course course = form; course.setInstructor(instructor); courseRepo.create(course, form.getFirstTermName()); redirectAttributes.addFlashAttribute("okMessageCode", "courseCreated"); return "redirect:/instructor/courses/" + course.getId(); } catch (RepositoryException e) { bindingResult.rejectValue("name", "courseWithThisNameAlreadyExists"); return "instructor/newCourse"; } }
From source file:com.github.dbourdette.otto.web.controller.sources.SourcesController.java
@RequestMapping(value = "/sources", method = RequestMethod.POST) public String createSource(@Valid @ModelAttribute("form") SourceForm form, BindingResult result) { if (StringUtils.isNotEmpty(form.getSize())) { try {// w w w .j av a2 s.c o m form.getSizeInBytes(); } catch (Exception e) { result.rejectValue("size", "size.invalidPattern"); } } if (Source.exists(form.getName())) { result.rejectValue("name", "source.alreadyExists"); } if (result.hasErrors()) { return "sources/source_form"; } Source.create(form); flashScope.message("source " + form.getName() + " has just been created"); return "redirect:/sources/" + form.getName() + "/configuration"; }