List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)
From source file:org.bibsonomy.webapp.validation.opensocial.BibSonomyOAuthValidator.java
@Override public void validate(Object oAuthObject, Errors errors) { OAuthAdminCommand command = (OAuthAdminCommand) oAuthObject; if (KeyType.RSA_PRIVATE.equals(command.getConsumerInfo().getKeyType())) { // check wheter consumer secret is a valid (pem) encoded certificate try {/*from w w w .ja v a 2 s .c o m*/ this.getPublicKeyFromPem(command.getConsumerInfo().getConsumerSecret()); } catch (Exception e) { errors.rejectValue("consumerInfo.consumerSecret", "error.oauth.rsa.pubKey"); } } // Check whether required fields are empty if (AdminAction.Register.equals(command.getAdminAction_())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.consumerKey", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.consumerSecret", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.serviceName", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.keyType", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.keyName", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.title", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.summary", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "consumerInfo.description", "error.field.required"); } }
From source file:org.broadleafcommerce.core.web.checkout.validator.CheckoutFormValidator.java
public void validate(Object obj, Errors errors) { CheckoutForm checkoutForm = (CheckoutForm) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.addressLine1", "addressLine1.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.phonePrimary", "phone.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.city", "city.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postalCode", "postalCode.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.addressLine1", "addressLine1.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.city", "city.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.postalCode", "postalCode.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardNumber", "creditCardNumber.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardCvvCode", "creditCardCvvCode.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpMonth", "creditCardExpMonth.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpYear", "creditCardExpYear.required"); if (!errors.hasErrors()) { if (!GenericValidator.isEmail(checkoutForm.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); }//from w ww . ja v a 2 s. co m } }
From source file:org.broadleafcommerce.core.web.checkout.validator.OrderInfoFormValidator.java
public void validate(Object obj, Errors errors) { OrderInfoForm orderInfoForm = (OrderInfoForm) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); if (!errors.hasErrors()) { if (!EmailValidator.getInstance().isValid(orderInfoForm.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); }// www . ja v a 2 s. com } }
From source file:org.broadleafcommerce.core.web.controller.account.validator.UpdateAccountValidator.java
public void validate(UpdateAccountForm form, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); if (!errors.hasErrors()) { //is this a valid email address? if (!GenericValidator.isEmail(form.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid"); }//from w w w . j a va 2 s . c o m //check email address to see if it is already in use by another customer Customer customerMatchingNewEmail = customerService.readCustomerByEmail(form.getEmailAddress()); if (customerMatchingNewEmail != null && !CustomerState.getCustomer().getId().equals(customerMatchingNewEmail.getId())) { //customer found with new email entered, and it is not the current customer errors.rejectValue("emailAddress", "emailAddress.used"); } } }
From source file:org.broadleafcommerce.profile.core.service.validator.RegistrationValidator.java
public void validate(Customer customer, String password, String passwordConfirm, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath();/*from w ww. j a va 2 s .c o m*/ if (errors.hasErrors()) { if (!passwordConfirm.equals(password)) { errors.rejectValue("passwordConfirm", "invalid"); } if (!customer.getFirstName().matches(validNameRegex)) { errors.rejectValue("firstName", "firstName.invalid", null, null); } if (!customer.getLastName().matches(validNameRegex)) { errors.rejectValue("lastName", "lastName.invalid", null, null); } if (!customer.getPassword().matches(validPasswordRegex)) { errors.rejectValue("password", "password.invalid", null, null); } if (!password.equals(passwordConfirm)) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(customer.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); } } }
From source file:org.broadleafcommerce.profile.web.controller.CustomerPhoneController.java
/** * Creates a new phone if no customerPhoneId & phoneId are passed in; otherwise, it creates a new customerPhone object otherwise. If they are passed in, * it is assumed that there is an update. * * @param phoneNameForm//ww w. j a va2s . co m * @param errors * @param request * @param customerPhoneId DOCUMENT ME! * @param phoneId DOCUMENT ME! * * @return */ @RequestMapping(value = "savePhone", method = { RequestMethod.GET, RequestMethod.POST }) public String savePhone(@ModelAttribute("phoneNameForm") PhoneNameForm phoneNameForm, BindingResult errors, HttpServletRequest request, @RequestParam(required = false) Long customerPhoneId, @RequestParam(required = false) Long phoneId) { if (GenericValidator.isBlankOrNull(phoneNameForm.getPhoneName())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phoneName", "phoneName.required"); } if (phoneId != null) { phoneNameForm.getPhone().setId(phoneId); } phoneFormatter.formatPhoneNumber(phoneNameForm.getPhone()); errors.pushNestedPath("phone"); phoneValidator.validate(phoneNameForm.getPhone(), errors); errors.popNestedPath(); if (!errors.hasErrors()) { CustomerPhone customerPhone = (CustomerPhone) entityConfiguration .createEntityInstance("org.broadleafcommerce.profile.core.domain.CustomerPhone"); customerPhone.setCustomer(customerState.getCustomer(request)); customerPhone.setPhoneName(phoneNameForm.getPhoneName()); customerPhone.setPhone(phoneNameForm.getPhone()); if ((customerPhoneId != null) && (customerPhoneId > 0)) { customerPhone.setId(customerPhoneId); } customerPhoneValidator.validate(customerPhone, errors); if (!errors.hasErrors()) { customerPhone = customerPhoneService.saveCustomerPhone(customerPhone); request.setAttribute("customerPhoneId", customerPhone.getId()); request.setAttribute("phoneId", customerPhone.getPhone().getId()); } return savePhoneSuccessView; } else { return savePhoneErrorView; } }
From source file:org.broadleafcommerce.profile.web.controller.validator.RegisterCustomerValidator.java
public void validate(Object obj, Errors errors, boolean useEmailForUsername) { RegisterCustomerForm form = (RegisterCustomerForm) obj; Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername()); if (customerFromDb != null) { if (useEmailForUsername) { errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null); } else {/*www .j a v a 2 s.c o m*/ errors.rejectValue("customer.username", "username.used", null, null); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (!errors.hasErrors()) { if (!form.getPassword().matches(getValidatePasswordExpression())) { errors.rejectValue("password", "password.invalid", null, null); } if (!form.getPassword().equals(form.getPasswordConfirm())) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) { errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null); } } }
From source file:org.commonwl.view.workflow.WorkflowFormValidator.java
/** * Validates a WorkflowForm to ensure the URL is not empty and links to a cwl file * @param form The given WorkflowForm/*from w w w. ja v a 2s . co m*/ * @param e Any errors from validation */ public GitDetails validateAndParse(WorkflowForm form, Errors e) { ValidationUtils.rejectIfEmptyOrWhitespace(e, "url", "url.emptyOrWhitespace"); // If not null and isn't just whitespace if (!e.hasErrors()) { // Override if specific branch or path is given in the form String repoUrl = null; String branch = null; String path = null; String packedId = null; if (!isEmptyOrWhitespace(form.getBranch())) { branch = form.getBranch(); } if (!isEmptyOrWhitespace(form.getPath())) { path = form.getPath(); } if (!isEmptyOrWhitespace(form.getPackedId())) { packedId = form.getPackedId(); } // Github URL Matcher m = githubCwlPattern.matcher(form.getUrl()); if (m.find()) { repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git"; if (branch == null) branch = m.group(3); if (path == null) path = m.group(4); } // Gitlab URL m = gitlabCwlPattern.matcher(form.getUrl()); if (m.find()) { repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git"; if (branch == null) branch = m.group(3); if (path == null) path = m.group(4); } // Github Dir URL m = githubDirPattern.matcher(form.getUrl()); if (m.find() && !m.group(2).endsWith(".git")) { repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git"; if (branch == null) branch = m.group(3); if (path == null) path = m.group(4); } // Gitlab Dir URL m = gitlabDirPattern.matcher(form.getUrl()); if (m.find() && !m.group(2).endsWith(".git")) { repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git"; if (branch == null) branch = m.group(3); if (path == null) path = m.group(4); } // Split off packed ID if present if (repoUrl != null) { GitDetails details = new GitDetails(repoUrl, branch, path); if (packedId != null) { details.setPackedId(packedId); } else { String[] pathSplit = path.split("#"); if (pathSplit.length > 1) { details.setPath(pathSplit[pathSplit.length - 2]); details.setPackedId(pathSplit[pathSplit.length - 1]); } } return details; } // General Git details if didn't match the above ValidationUtils.rejectIfEmptyOrWhitespace(e, "branch", "branch.emptyOrWhitespace"); if (!e.hasErrors()) { m = gitRepoPattern.matcher(form.getUrl()); if (m.find()) { GitDetails details = new GitDetails(form.getUrl(), form.getBranch(), form.getPath()); details.setPackedId(form.getPackedId()); return details; } } } // Errors will stop this being used anyway return null; }
From source file:org.egov.council.web.controller.CouncilCasteController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public String create(@Valid @ModelAttribute final CouncilCaste councilCaste, final BindingResult errors, final Model model, final RedirectAttributes redirectAttrs) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "notempty.cncl.caste"); if (errors.hasErrors()) { return COUNCILCASTE_NEW; }/*from w w w . ja va 2 s. c om*/ councilCasteService.create(councilCaste); redirectAttrs.addFlashAttribute("message", messageSource.getMessage("msg.councilCaste.success", null, null)); return "redirect:/councilcaste/result/" + councilCaste.getId(); }
From source file:org.egov.council.web.controller.CouncilCasteController.java
@RequestMapping(value = "/update", method = RequestMethod.POST) public String update(@Valid @ModelAttribute final CouncilCaste councilCaste, final BindingResult errors, final Model model, final RedirectAttributes redirectAttrs) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "notempty.cncl.caste"); if (errors.hasErrors()) { return COUNCILCASTE_EDIT; }/*from w w w.j a va 2s . c o m*/ councilCasteService.update(councilCaste); redirectAttrs.addFlashAttribute("message", messageSource.getMessage("msg.councilCaste.success", null, null)); return "redirect:/councilcaste/result/" + councilCaste.getId(); }