List of usage examples for org.springframework.validation BeanPropertyBindingResult rejectValue
@Override
public void rejectValue(@Nullable String field, String errorCode, String defaultMessage)
From source file:org.toobsframework.social.session.registration.ValidateRegistration.java
@Handler public DispatchContext validateUser(DispatchContext context) throws ValidationException { User user = (User) context.getContextObject(); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(user, "user"); if (user.getFirstName() == null || user.getFirstName().trim().length() == 0) { errors.rejectValue("firstName", "first.name.missing", "first name needs to be provided"); }/*from w w w. j a va 2 s . c o m*/ if (user.getLastName() == null || user.getLastName().trim().length() == 0) { errors.rejectValue("lastName", "last.name.missing", "last name needs to be provided"); } if (user.getUserId() == null || user.getUserId().trim().length() == 0) { errors.rejectValue("userId", "email.missing", "email needs to be provided"); } if (user.getPassword() == null || user.getPassword().trim().length() < 6) { errors.rejectValue("password", "password.too.short", "password needs to be at least 6 characters"); } User existingUser = dao.getUser(user.getUserId()); if (existingUser != null) { errors.reject("user.exists", "user with email " + user.getUserId() + " already exists"); } if (errors.hasErrors()) { throw new ValidationException(errors); } return context; }
From source file:org.hdiv.web.servlet.tags.form.InputTagTests.java
public void testWithErrors() throws Exception { this.tag.setPath("name"); this.tag.setCssClass("good"); this.tag.setCssErrorClass("bad"); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME); errors.rejectValue("name", "some.code", "Default Message"); errors.rejectValue("name", "too.short", "Too Short"); exposeBindingResult(errors);//from w w w .j a va 2 s . co m assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getWriter().toString(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, "Rob"); assertContainsAttribute(output, "class", "bad"); }
From source file:org.commonwl.view.workflow.WorkflowController.java
/** * Get a workflow from Git Details, creating if it does not exist * @param gitDetails The details of the Git repository * @param redirectAttrs Error attributes for redirect * @return The model and view to be returned by the controller *//* w w w . j a v a 2 s .c o m*/ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redirectAttrs) { // Get workflow QueuedWorkflow queued = null; Workflow workflowModel = workflowService.getWorkflow(gitDetails); if (workflowModel == null) { // Check if already queued queued = workflowService.getQueuedWorkflow(gitDetails); if (queued == null) { // Validation String packedPart = (gitDetails.getPackedId() == null) ? "" : "#" + gitDetails.getPackedId(); WorkflowForm workflowForm = new WorkflowForm(gitDetails.getRepoUrl(), gitDetails.getBranch(), gitDetails.getPath() + packedPart); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(workflowForm, "errors"); workflowFormValidator.validateAndParse(workflowForm, errors); if (!errors.hasErrors()) { try { if (gitDetails.getPath().endsWith(".cwl")) { queued = workflowService.createQueuedWorkflow(gitDetails); if (queued.getWorkflowList() != null) { // Packed workflow listing if (queued.getWorkflowList().size() == 1) { gitDetails.setPackedId(queued.getWorkflowList().get(0).getFileName()); return new ModelAndView("redirect:" + gitDetails.getInternalUrl()); } return new ModelAndView("selectworkflow", "workflowOverviews", queued.getWorkflowList()).addObject("gitDetails", gitDetails); } } else { List<WorkflowOverview> workflowOverviews = workflowService .getWorkflowsFromDirectory(gitDetails); if (workflowOverviews.size() > 1) { return new ModelAndView("selectworkflow", "workflowOverviews", workflowOverviews) .addObject("gitDetails", gitDetails); } else if (workflowOverviews.size() == 1) { return new ModelAndView("redirect:" + gitDetails.getInternalUrl() + workflowOverviews.get(0).getFileName()); } else { errors.rejectValue("url", "url.noWorkflowsInDirectory", "No workflow files were found in the given directory"); } } } catch (TransportException ex) { logger.warn("git.sshError " + workflowForm, ex); errors.rejectValue("url", "git.sshError", "SSH URLs are not supported, please provide a HTTPS URL for the repository or submodules"); } catch (GitAPIException ex) { logger.error("git.retrievalError " + workflowForm, ex); errors.rejectValue("url", "git.retrievalError", "The workflow could not be retrieved from the Git repository using the details given"); } catch (WorkflowNotFoundException ex) { logger.warn("git.notFound " + workflowForm, ex); errors.rejectValue("url", "git.notFound", "The workflow could not be found within the repository"); } catch (IOException ex) { logger.warn("url.parsingError " + workflowForm, ex); errors.rejectValue("url", "url.parsingError", "The workflow could not be parsed from the given URL"); } } // Redirect to main page with errors if they occurred if (errors.hasErrors()) { redirectAttrs.addFlashAttribute("errors", errors); return new ModelAndView("redirect:/?url=" + gitDetails.getUrl()); } } } // Display this model along with the view if (queued != null) { // Retry creation if there has been an error in cwltool parsing if (queued.getCwltoolStatus() == CWLToolStatus.ERROR) { workflowService.retryCwltool(queued); } return new ModelAndView("loading", "queued", queued); } else { return new ModelAndView("workflow", "workflow", workflowModel).addObject("formats", WebConfig.Format.values()); } }