List of usage examples for org.springframework.validation BindingResult hasErrors
boolean hasErrors();
From source file:com.spring.blueye.web.UserController.java
@RequestMapping(value = "/users/new", method = RequestMethod.POST) public String processCreationForm(@Valid User user, BindingResult result, SessionStatus status) { if (result.hasErrors()) { return "users/createOrUpdateUserForm"; } else {//from w ww.jav a2s .co m this.coreService.saveUser(user); status.setComplete(); return "redirect:/users/" + user.getId(); } }
From source file:com.spring.blueye.web.UserController.java
@RequestMapping(value = "/users/{userId}/edit", method = RequestMethod.PUT) public String processUpdateUserForm(@Valid User user, BindingResult result, SessionStatus status) { if (result.hasErrors()) { return "users/createOrUpdateUserForm"; } else {/*from w w w. j a va 2 s .c o m*/ this.coreService.saveUser(user); status.setComplete(); return "redirect:/users/{userId}"; } }
From source file:org.jblogcms.core.blog.controller.EditBlogController.java
/** * Submits form for adding new {@link Blog} * * @param blogForm the blog 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 *///w ww . ja va2 s .com @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/admin/blog/update/{blogId}", method = RequestMethod.POST) public String editBlogSubmitForm(@PathVariable("blogId") String blogId, @Valid @ModelAttribute("blog") Blog blogForm, BindingResult result, SessionStatus status, Model model) { if (result.hasErrors()) { return "admin/blogEdit"; } else { Blog blog = editBlog(blogForm, result); if (blog == null) { return "admin/blogEdit"; } status.setComplete(); return "redirect:/admin/blogs"; } }
From source file:org.sventon.web.ctrl.ConfigurationFormControllerTest.java
@Test public void onFormSubmitRepositoryAdded() throws Exception { Application application = mock(Application.class); HashSet<RepositoryName> repositoryNames = new HashSet<RepositoryName>(); repositoryNames.add(new RepositoryName("sventon")); repositoryNames.add(new RepositoryName("nordpolen")); when(application.getRepositoryNames()).thenReturn(repositoryNames); ConfigCommand command = new ConfigCommand(); command.setName("nordpolen"); command.setRepositoryUrl("svn://northpole.com/repo"); BindingResult bindingResult = mock(BindingResult.class); when(bindingResult.hasErrors()).thenReturn(false); Model model = new ExtendedModelMap(); ConfigurationFormController controller = new ConfigurationFormController(application); String listConfigView = controller.onFormSubmit(command, bindingResult, model); Map expectedModel = new HashMap(); expectedModel.put("addedRepositories", repositoryNames); expectedModel.put("latestAddedRepository", command.getName()); assertThat(listConfigView, is(LIST_CONFIGS_VIEW_NAME)); assertThat(model.asMap(), is(expectedModel)); }
From source file:org.terasoluna.tourreservation.app.reservetour.ReserveTourController.java
/** * Shows the confirmation page before reserving a tour * @param form//from w w w . j a va 2 s . c om * @param bindingResult * @param model * @return */ @TransactionTokenCheck(value = "reserve", type = TransactionTokenType.BEGIN) @RequestMapping(value = "reserve", method = RequestMethod.POST, params = "confirm") public String confirm(@AuthenticationPrincipal ReservationUserDetails userDetails, @Validated ReserveTourForm form, BindingResult bindingResult, Model model) { if (bindingResult.hasErrors()) { return "reservetour/reserveForm"; } logger.debug("confirm the reservation details for the following tour {}", form.getTourCode()); TourDetailOutput output = reserveTourHelper.findTourDetail(userDetails, form); model.addAttribute("output", output); return "reservetour/reserveConfirm"; }
From source file:cherry.example.web.applied.ex10.AppliedEx11ControllerImpl.java
private boolean hasErrors(int rownum, AppliedEx11Form form, BindingResult binding) { // ??// w ww. j a va 2 s . co m if (binding.hasErrors()) { return true; } // ? if (form.getItem().get(rownum).getDt() == null && form.getItem().get(rownum).getTm() != null) { LogicalErrorUtil.rejectValue(binding, AppliedEx11Form.getItemPropName(rownum, Prop.Dt), LogicalError.RequiredWhen, AppliedEx11Form.resolveItemProp(rownum, Prop.Dt), AppliedEx11Form.resolveItemProp(rownum, Prop.Tm)); } if (binding.hasErrors()) { return true; } // ?? return false; }
From source file:cherry.example.web.applied.ex20.AppliedEx21ControllerImpl.java
private boolean hasErrors(int rownum, AppliedEx21Form form, BindingResult binding) { // ??/*from w ww .ja va 2 s. c om*/ if (binding.hasErrors()) { return true; } // ? if (form.getItem().get(rownum).getDt() == null && form.getItem().get(rownum).getTm() != null) { LogicalErrorUtil.rejectValue(binding, AppliedEx21Form.getItemPropName(rownum, Prop.Dt), LogicalError.RequiredWhen, AppliedEx21Form.resolveItemProp(rownum, Prop.Dt), AppliedEx21Form.resolveItemProp(rownum, Prop.Tm)); } if (binding.hasErrors()) { return true; } // ?? return false; }
From source file:com.dub.skoolie.web.controller.system.schedule.SystemClassTimeBlockController.java
@RequestMapping(value = "/system/schedule/classtimeblock", method = RequestMethod.POST) public ModelAndView addClassTimeBlock(@Valid ClassTimeBlockBean classTimeBlockBean, BindingResult result, Model model, HttpServletRequest request) { String referrer = request.getHeader("Referer"); if (result.hasErrors()) { if (!referrer.equals("/system/schedule/classtimeblock")) { return new ModelAndView("redirect:" + referrer); }// ww w. j ava 2 s. c o m model.addAttribute("classTimeBlockBeans", uiClassTimeBlockServiceImpl.getClassTimeBlocks()); model.addAttribute("classTimeBlockBean", classTimeBlockBean); model.addAttribute("gradingPeriods", uiClassTimeBlockServiceImpl.getGradingPeriods()); return new ModelAndView("system/schedule/classtimeblock"); } uiClassTimeBlockServiceImpl.addClassTimeBlock(classTimeBlockBean); return new ModelAndView("redirect:" + referrer); }
From source file:com.dub.skoolie.web.controller.system.school.SystemSchoolController.java
@RequestMapping(value = "/system/schools", method = RequestMethod.POST) public ModelAndView addSchool(@Valid SchoolBean schoolBean, BindingResult result, Model model, HttpServletRequest request) {//ww w .ja v a2 s .co m String referrer = request.getHeader("Referer"); if (result.hasErrors()) { if (!referrer.equals("/system/schools")) { return new ModelAndView("redirect:" + referrer); } model.addAttribute("schoolBean", schoolBean); model.addAttribute("schools", uiSchoolServiceImpl.getSchools()); return new ModelAndView("system/school/schools"); } uiSchoolServiceImpl.addSchool(schoolBean); return new ModelAndView("redirect:" + referrer); }
From source file:com.github.lynxdb.server.api.http.handlers.EpPut.java
@RequestMapping(path = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity put(Authentication _authentication, @RequestBody @Valid List<Metric> _request, BindingResult _bindingResult) { User user = (User) _authentication.getPrincipal(); if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); });//w w w .ja v a2 s .c o m return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString(), null).response(); } List<com.github.lynxdb.server.core.Metric> metricList = new ArrayList<>(); _request.stream().forEach((m) -> { metricList.add(new com.github.lynxdb.server.core.Metric(m)); }); try { entries.insertBulk(vhosts.byId(user.getVhost()), metricList); } catch (Exception ex) { throw ex; } return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); }