List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)
From source file:com.minhthuong.pfi.validator.PeopleValidator.java
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) *//*from w ww.jav a 2s .c o m*/ public void validate(Object target, Errors errors) { log.info("validator object"); AddPeopleForm form = (AddPeopleForm) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "NotEmpty.people.name"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address", "NotEmpty.people.address"); String name = form.getName(); if (name.length() > 100 || name.length() < 10) { errors.rejectValue("name", "fieldLength"); } }
From source file:edu.wisc.my.portlets.bookmarks.domain.validation.EntryValidator.java
private void validateName(Entry entry, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "portlet.entry.error.name.required"); }
From source file:com.virtusa.akura.common.validator.GradeSubjectValidator.java
/** * Validates objects of the GradeSubject. * * @param target - Populated object of GradeSubject to validate * @param errors - Errors object that is building. May contain errors for the fields relating to types. *//*from w w w. j a v a2 s . com*/ public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, GRADE_ID, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE); GradeSubject gradeSubject = (GradeSubject) target; if (gradeSubject.getGrade().getGradeId() == 0) { errors.rejectValue(GRADE_ID, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE); } }
From source file:org.pdfgal.pdfgalweb.validators.UnProtectValidator.java
@Override public void validate(final Object target, final Errors errors) { final UnProtectForm unProtectForm = (UnProtectForm) target; // File validation final MultipartFile file = unProtectForm.getFile(); this.validatorUtils.validateFile(file, errors, PDFEncryptionType.ENCRYPTED); // Password validation ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "common.validator.required"); }
From source file:org.guanxi.idp.form.RegisterSPFormValidator.java
public void validate(Object obj, Errors errors) { RegisterSP form = (RegisterSP) obj;//from w w w. j av a 2 s .co m if (checkForDuplicateSP(form.getProviderId())) { errors.rejectValue("providerId", "register.sp.error.duplicate.providerId"); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "providerId", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "identity", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creds", "error.field.required"); }
From source file:org.guanxi.sp.engine.form.RegisterGuardFormValidator.java
public void validate(Object obj, Errors errors) { RegisterGuard form = (RegisterGuard) obj; if (checkForDuplicateGuard(form.getGuardid())) { errors.rejectValue("guardid", "register.guard.error.duplicate.guardid"); }/*from w w w. j a va 2 s . co m*/ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "guardid", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "scheme", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "port", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "url", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "applicationName", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "orgunit", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "org", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "city", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "locality", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contactCompany", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contactGivenName", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contactSurname", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contactEmail", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contactPhone", "error.field.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "country", "error.field.required"); }
From source file:com.h57.sample.validator.RegistrationValidator.java
public void validate(Object obj, Errors e) { RegistrationForm r = (RegistrationForm) obj; /**//from w w w . j a va 2 s .c om * Username Validation Can't be Empty Must be Alpha Numeric Must be greater * than 3 characters Mush be less than 50 characters TODO: Need to check the * DB to verify the userID isn't already in use. */ ValidationUtils.rejectIfEmptyOrWhitespace(e, "username", "username.empty"); if (this.isNotAlphaNumeric(r.getUsername())) { e.rejectValue("username", "username.notAlphaNumberic"); } if (r.getUsername().length() < 3) { e.rejectValue("username", "username.toShort"); } if (r.getUsername().length() > 50) { e.rejectValue("username", "username.toLong"); } /** * Passphrase Validation Can't be Empty Must be greater than 8 characters * Mush be less than 50 characters */ ValidationUtils.rejectIfEmptyOrWhitespace(e, "passphrase", "passphrase.empty"); if (r.getUsername().length() < 8) { e.rejectValue("passphrase", "passphrase.toShort"); } if (r.getUsername().length() > 50) { e.rejectValue("passphrase", "passphrase.toLong"); } /** * Email Validation Can't be Empty TODO: Need to check the DB to verify the * email isn't already in use. */ ValidationUtils.rejectIfEmptyOrWhitespace(e, "email", "email.empty"); }
From source file:edu.wisc.my.portlets.bookmarks.domain.validation.CollectionValidator.java
private void validateUrl(CollectionFolder collection, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "url", "portlet.bookmark.error.url.required"); String url = collection.getUrl(); collection.setUrl(url);//w ww . j a va 2 s . c om try { new URL(url); } catch (MalformedURLException mue) { errors.rejectValue("url", "portlet.bookmark.error.url.malformed"); } }
From source file:org.pdfgal.pdfgalweb.validators.ProtectValidator.java
@Override public void validate(final Object target, final Errors errors) { final ProtectForm protectForm = (ProtectForm) target; // File validation final MultipartFile file = protectForm.getFile(); this.validatorUtils.validateFile(file, errors, PDFEncryptionType.NON_ENCRYPTED); // Password validation ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "common.validator.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "repeatedPassword", "common.validator.required"); final String password = protectForm.getPassword(); final String repeatedPassword = protectForm.getRepeatedPassword(); if (StringUtils.isNotBlank(password) && StringUtils.isNotBlank(repeatedPassword) && !password.equals(repeatedPassword)) { errors.rejectValue("repeatedPassword", "protect.validator.passwords"); }// w ww .j a v a 2s.c o m }
From source file:com.virtusa.akura.common.validator.RaceValidator.java
/** * Validates the object of the Race./* w w w . j a v a 2 s. c om*/ * * @param target - Populated object of Race to validate * @param errors - Errors object that is building. May contain errors for the fields relating to types. */ public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, DESCRIPTION, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE); Race race = (Race) target; String validatorPattern = ValidatorExpressionUtil.getValidatorPattern("REFERENCE.RACE.VALIDATOR"); Pattern stringOnly = Pattern.compile(validatorPattern); Matcher makeMatch = stringOnly.matcher(race.getDescription()); if (makeMatch.find()) { errors.rejectValue(DESCRIPTION, AkuraWebConstant.MISMATCH_ERROR); } }