List of usage examples for org.springframework.validation BindingResult getErrorCount
int getErrorCount();
From source file:org.cloudfoundry.identity.uaa.config.YamlBindingTests.java
@Test public void testBindErrorNotWritable() { expected.expectMessage("property 'spam'"); expected.expectMessage("not writable"); VanillaTarget target = new VanillaTarget(); BindingResult result = bind(target, "spam: bar\nvalue: 123"); assertEquals(1, result.getErrorCount()); }
From source file:org.codeqinvest.web.project.CreateProjectController.java
/** * This methods handles the submitted form for creating a new project. *//* ww w . j a v a2s.co m*/ @RequestMapping(value = "/create", method = RequestMethod.POST) ModelAndView create(@ModelAttribute Project project, BindingResult bindingResult, @ModelAttribute("retrievedSonarProjectsAsJson") String sonarProjects, Model model) { projectConnectionsValidator.validate(project, bindingResult); if (bindingResult.hasErrors()) { log.info("Rejected creation of project due {} validation errors", bindingResult.getErrorCount()); if (log.isDebugEnabled()) { for (FieldError fieldError : bindingResult.getFieldErrors()) { log.debug("Field {} has following error: {}", fieldError.getField(), fieldError.getCode()); } } addDeserializedSonarProjectsToModel(sonarProjects, model); model.addAttribute("fieldErrors", bindingResult.getFieldErrors()); return new ModelAndView("createProject"); } // this little hack is necessary until a better way for binding the value from the form is found CodeChangeSettings codeChangeSettings = project.getCodeChangeSettings(); if (codeChangeSettings.getMethod() == SupportedCodeChangeProbabilityMethod.COMMIT_BASED.getId()) { codeChangeSettings.setNumberOfCommits(codeChangeSettings.getDays()); codeChangeSettings.setDays(null); } Project addedProject = projectRepository.save(project); analyzerScheduler.scheduleAnalyzer(addedProject); log.info("Created project {} and scheduled its quality analysis", project.getName()); RedirectView redirect = new RedirectView("/projects/" + addedProject.getId()); redirect.setExposeModelAttributes(false); return new ModelAndView(redirect); }
From source file:org.codeqinvest.web.sonar.SonarController.java
/** * This route can be used by JavaScript frontend code to retrieve all available * projects of a given Sonar server.//from w w w . j a v a 2 s. c o m */ @RequestMapping(value = "/projects", method = RequestMethod.PUT) @ResponseBody Set<ProjectInformation> allProjects(@RequestBody SonarServer sonarServer, BindingResult errors, HttpServletResponse response) { sonarServerValidator.validate(sonarServer, errors); if (errors.hasErrors()) { // TODO could be improved with exception and corresponding exception handler log.info("Rejected retrieving all projects from Sonar server {} due {} validation errors", sonarServer, errors.getErrorCount()); response.setStatus(BAD_REQUEST); return null; } Set<ProjectInformation> projects = projectsCollectorService .collectAllProjects(sonarServer.getConnectionSettings()); log.info("Found {} projects for sonar server at {}", projects.size(), sonarServer); return projects; }
From source file:org.jtalks.common.web.controller.UserControllerTest.java
@Test public void testRegisterDuplicateUser() throws Exception { RegisterUserDto dto = getRegisterUserDto(); BindingResult bindingResult = new BeanPropertyBindingResult(dto, "newUser"); doThrow(new DuplicateUserException("User username already exists!")).when(userService) .registerUser(Matchers.any(User.class)); ModelAndView mav = controller.registerUser(dto, bindingResult); assertViewName(mav, "registration"); assertEquals(bindingResult.getErrorCount(), 1, "Result without errors"); verify(userService).registerUser(Matchers.any(User.class)); }
From source file:org.jtalks.common.web.controller.UserControllerTest.java
@Test public void testRegisterUserWithDuplicateEmail() throws Exception { RegisterUserDto dto = getRegisterUserDto(); BindingResult bindingResult = new BeanPropertyBindingResult(dto, "newUser"); doThrow(new DuplicateEmailException("E-mail mail@mail.com already exists!")).when(userService) .registerUser(Matchers.any(User.class)); ModelAndView mav = controller.registerUser(dto, bindingResult); assertViewName(mav, "registration"); assertEquals(bindingResult.getErrorCount(), 1, "Result without errors"); verify(userService).registerUser(Matchers.any(User.class)); }
From source file:org.easyj.rest.controller.AbstractGenericEntityController.java
protected ModelAndView save(E entity, BindingResult result, String viewName) { if (entity == null || result == null) { logger.debug("ERROR: Cannot save: some parameter is null entity[{}], result[{}]", new Object[] { entity, result }); throw new BadRequestException(configMAV(entity, result, getEditViewName())); } else {/* w ww. j a v a2 s .c o m*/ for (Validator val : getValidators()) { val.validate(entity, result); } if (result.hasErrors()) { logger.debug("ERROR: Cannot save: missing or wrong parameters: ERRORS FOUND[{}]", result.getErrorCount()); throw new BadRequestException(configMAV(entity, result, getEditViewName())); } else { logger.debug("Entity SAVING: entity[" + entity + "]"); E retEntity = persist(entity); logger.debug("Entity SAVED: entity[" + entity + "]"); return configMAV(retEntity, result, viewName); } } }
From source file:com.minhthuong.pfi.controller.PFIViewController.java
@ActionMapping(params = "action=submitPeople") public void submitPeople(AddPeopleForm formBean, BindingResult result, SessionStatus status, ActionResponse response) {/*ww w . ja v a 2s . c o m*/ log.log(Level.INFO, "submitPeople.START"); peopleValidator.validate(formBean, result); if (!result.hasErrors()) { try { People people = new People(); BeanUtils.copyProperties(people, formBean); peopleService.addPeople(people); } catch (Exception e) { log.log(Level.SEVERE, "Error during saving people"); } // Prepare parameter to render phase response.setRenderParameter("show", "list_people"); } else { log.log(Level.INFO, "Error in binding result:" + result.getErrorCount()); response.setRenderParameter("show", "add_people"); } }
From source file:org.jtalks.common.web.controller.UserControllerTest.java
@Test public void testEditProfileWrongPassword() throws Exception { EditUserProfileDto userDto = getEditUserProfileDto(); BindingResult bindingResult = new BeanPropertyBindingResult(userDto, "editedUser"); doThrow(new WrongPasswordException()).when(userService).editUserProfile(userDto.getEmail(), userDto.getFirstName(), userDto.getLastName(), userDto.getCurrentUserPassword(), userDto.getNewUserPassword(), userDto.getAvatar().getBytes()); ModelAndView mav = controller.editProfile(userDto, bindingResult); assertViewName(mav, "editProfile"); assertEquals(bindingResult.getErrorCount(), 1, "Result without errors"); verify(userService).editUserProfile(userDto.getEmail(), userDto.getFirstName(), userDto.getLastName(), userDto.getCurrentUserPassword(), userDto.getNewUserPassword(), userDto.getAvatar().getBytes()); assertContainsError(bindingResult, "currentUserPassword"); }