Java Code Examples for org.springframework.validation.ValidationUtils#rejectIfEmptyOrWhitespace()
The following examples show how to use
org.springframework.validation.ValidationUtils#rejectIfEmptyOrWhitespace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexValidator.java From Spring-MVC-Blueprints with MIT License | 7 votes |
@Override public void validate(Object obj, Errors errors) { Home homeForm = (Home) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "message", "message.empty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "quote", "quote.empty"); if(homeForm.getMessage().length() > 500){ errors.rejectValue("message", "message.maxlength"); } if(homeForm.getMessage().length() < 50){ errors.rejectValue("message", "message.minlength"); } if(homeForm.getQuote().length() > 500){ errors.rejectValue("quote", "quote.maxlength"); } if(homeForm.getQuote().length() < 50){ errors.rejectValue("quote", "quote.minlength"); } }
Example 2
Source File: UserValidator.java From yugastore-java with Apache License 2.0 | 6 votes |
@Override public void validate(Object o, Errors errors) { User user = (User) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty"); if (user.getUsername().length() < 6 || user.getUsername().length() > 32) { errors.rejectValue("username", "Size.userForm.username"); } if (userService.findByUsername(user.getUsername()) != null) { errors.rejectValue("username", "Duplicate.userForm.username"); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty"); if (user.getPassword().length() < 8 || user.getPassword().length() > 32) { errors.rejectValue("password", "Size.userForm.password"); } if (!user.getPasswordConfirm().equals(user.getPassword())) { errors.rejectValue("passwordConfirm", "Diff.userForm.passwordConfirm"); } }
Example 3
Source File: UserValidator.java From registration-login-spring-xml-maven-jsp-mysql with MIT License | 6 votes |
@Override public void validate(Object o, Errors errors) { User user = (User) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty"); if (user.getUsername().length() < 6 || user.getUsername().length() > 32) { errors.rejectValue("username", "Size.userForm.username"); } if (userService.findByUsername(user.getUsername()) != null) { errors.rejectValue("username", "Duplicate.userForm.username"); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty"); if (user.getPassword().length() < 8 || user.getPassword().length() > 32) { errors.rejectValue("password", "Size.userForm.password"); } if (!user.getPasswordConfirm().equals(user.getPassword())) { errors.rejectValue("passwordConfirm", "Diff.userForm.passwordConfirm"); } }
Example 4
Source File: TeapotValidator.java From example-restful-project with MIT License | 6 votes |
/** * Validates or rejects the {@link Teapot} object. */ @Override public void validate(Object obj, Errors errors) { /* Id must be defined */ ValidationUtils.rejectIfEmptyOrWhitespace( errors, "id", "errIdUdefined", ERR_ID_UNDEFINED); /* Name must be defined */ ValidationUtils.rejectIfEmptyOrWhitespace( errors, "name", "errNameUndefined", ERR_NAME_UNDEFINED); Teapot teapot = (Teapot) obj; /* Check id against pattern */ if (!ID_PATTERN.matcher(teapot.getId()).matches()) { errors.rejectValue("id", "errIdBadFormat", ERR_ID_BAD_FORMAT); } /* Check if volume is in the list of valid volumes */ if (!Arrays.asList(VALID_VOLUMES).contains(teapot.getVolume())) { errors.rejectValue("volume", "errBadVolume", ERR_BAD_VOLUME); } }
Example 5
Source File: AgencyValidator.java From webcurator with Apache License 2.0 | 6 votes |
/** @see org.springframework.validation.Validator#validate(Object, Errors). */ public void validate(Object aCmd, Errors aErrors) { AgencyCommand cmd = (AgencyCommand) aCmd; ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, AgencyCommand.PARAM_ACTION, "required", getObjectArrayForLabel(AgencyCommand.PARAM_ACTION), "Action command is a required field."); if (AgencyCommand.ACTION_SAVE.equals(cmd.getActionCommand())) { ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, AgencyCommand.PARAM_NAME, "required", getObjectArrayForLabel(AgencyCommand.PARAM_NAME), "Agency name is a required field."); ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, AgencyCommand.PARAM_ADDRESS, "required", getObjectArrayForLabel(AgencyCommand.PARAM_ADDRESS), "Agency address is a required field."); ValidatorUtil.validateStringMaxLength(aErrors, cmd.getName(),80,"string.maxlength",getObjectArrayForLabelAndInt(AgencyCommand.PARAM_NAME,80),"Name field too long"); ValidatorUtil.validateStringMaxLength(aErrors, cmd.getAddress(),255,"string.maxlength",getObjectArrayForLabelAndInt(AgencyCommand.PARAM_ADDRESS,255),"Address field too long"); if (cmd.getEmail() != null && cmd.getEmail().length() > 0) { ValidatorUtil.validateRegEx(aErrors, cmd.getEmail(), ValidatorUtil.EMAIL_VALIDATION_REGEX, "invalid.email",getObjectArrayForLabel(AgencyCommand.PARAM_EMAIL),"the email address is invalid" ); } if (cmd.getAgencyURL() != null && cmd.getAgencyURL().length() > 0) { ValidatorUtil.validateURL(aErrors, cmd.getAgencyURL(),"invalid.url",new Object[] {cmd.getAgencyURL()},"Invalid URL"); } if (cmd.getAgencyLogoURL() != null && cmd.getAgencyLogoURL().length() > 0) { ValidatorUtil.validateURL(aErrors, cmd.getAgencyLogoURL(),"invalid.url",new Object[] {cmd.getAgencyLogoURL()},"Invalid URL"); } } }
Example 6
Source File: SignupValidator.java From java-course-ee with MIT License | 5 votes |
public void validate(Object o, Errors errors) { SignupCommand command = (SignupCommand) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.username.empty", "Please specify a username."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty", "Please specify an email address."); if (StringUtils.hasText(command.getEmail()) && !Pattern.matches(SIMPLE_EMAIL_REGEX, command.getEmail().toUpperCase())) { errors.rejectValue("email", "error.email.invalid", "Please enter a valid email address."); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty", "Please specify a password."); }
Example 7
Source File: GeneralValidator.java From webcurator with Apache License 2.0 | 5 votes |
/** @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) */ public void validate(Object comm, Errors errors) { GeneralCommand command = (GeneralCommand) comm; if(command.isEditMode()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", getObjectArrayForLabel(GeneralCommand.PARAM_NAME), "Name is a required field"); if(command.getName() != null) { ValidatorUtil.validateValueNotContained(errors, command.getName(), command.getSubGroupSeparator(), "string.contains", getObjectArrayForLabelAndValue(GeneralCommand.PARAM_NAME, command.getSubGroupSeparator()), "'"+command.getSubGroupSeparator()+"' cannot be a sub-string of Name"); } if(command.getSubGroupType().equals(command.getType()) && !GeneralCommand.ACTION_ADD_PARENT.equals(command.getAction())) { //Attempt to move page without setting a parent ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentOid", "required", getObjectArrayForLabel(GeneralCommand.PARAM_PARENT_OID), "Parent Group is a required field"); } ValidatorUtil.validateStringMaxLength(errors, command.getName(), GeneralCommand.CNST_MAX_LEN_NAME, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_NAME, GeneralCommand.CNST_MAX_LEN_NAME), "Name is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getDescription(), GeneralCommand.CNST_MAX_LEN_DESC, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_DESCRIPTION, GeneralCommand.CNST_MAX_LEN_DESC), "Description is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getOwnershipMetaData(), GeneralCommand.CNST_MAX_LEN_OWNER_INFO, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_OWNER_INFO, GeneralCommand.CNST_MAX_LEN_OWNER_INFO), "Owner info is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getType(), TargetGroup.MAX_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_TYPE, TargetGroup.MAX_TYPE_LENGTH), "Group Type is too long."); if (!errors.hasErrors()) { if (command.getFromDate() != null && command.getToDate() != null) { ValidatorUtil.validateStartBeforeEndTime(errors, command.getFromDate(), command.getToDate(), "time.range", new Object[] {"To date", "From date"}, "To date is before from date"); } } } }
Example 8
Source File: UserProfileValidator.java From cqrs-es-kafka with MIT License | 5 votes |
@Override public void validate(final Object profile, final Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, UserProfile.FIELD_USERNAME, MessageKeys.UserProfile.EMPTY_USERNAME); ValidationUtils.rejectIfEmptyOrWhitespace(errors, UserProfile.FIELD_EMAIL, MessageKeys.UserProfile.EMPTY_EMAIL); ValidationUtils.rejectIfEmptyOrWhitespace(errors, UserProfile.FIELD_PASSWORD, MessageKeys.UserProfile.EMPTY_PASSWORD); this.rejectIfNotEmail((UserProfile) profile, errors); this.rejectIfNotUsername((UserProfile) profile, errors); }
Example 9
Source File: ProfilesFormCredentialsValidator.java From webcurator with Apache License 2.0 | 5 votes |
public void validate(Object comm, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "credentialsDomain", "required", getObjectArrayForLabel("credentialsDomain"), "credentialsDomain is a required field"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginUri", "required", getObjectArrayForLabel("loginUri"), "Login URI is a required field"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "usernameField", "required", getObjectArrayForLabel("usernameField"), "usernameField is a required field"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "required", getObjectArrayForLabel("username"), "Username is a required field"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordField", "required", getObjectArrayForLabel("passwordField"), "Password is a required field"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "required", getObjectArrayForLabel("password"), "Password is a required field"); }
Example 10
Source File: ReportEmailAddressValidator.java From code-examples with MIT License | 5 votes |
public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "field.required"); ReportProperties reportProperties = (ReportProperties) target; if (!reportProperties.getEmailAddress().endsWith(EMAIL_DOMAIN)) { errors.rejectValue("emailAddress", "field.domain.required", new Object[]{EMAIL_DOMAIN}, "The email address must contain [" + EMAIL_DOMAIN + "] domain"); } }
Example 11
Source File: WidgetValidator.java From attic-rave with Apache License 2.0 | 5 votes |
/** * Checks if the required fields contain a value * * @param errors {@link Errors} */ private void validateRequiredFields(Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "widget.title.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_URL, "widget.url.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "type", "widget.type.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "widget.description.required"); }
Example 12
Source File: EmployeeValidator.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Override public void validate(Object model, Errors errors) { EmployeeForm empForm = (EmployeeForm) model; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "empty.firstName"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "empty.lastName"); if(empForm.getAge() < 0) errors.rejectValue("age", "negative.age"); if(empForm.getAge() > 65) errors.rejectValue("age", "retirable.age"); if(empForm.getBirthday().before(new Date(50,0,1))) errors.rejectValue("birthday", "old.birthday"); Date now = new Date(); if(empForm.getBirthday().getYear() == now.getYear() || empForm.getBirthday().before(new Date(99,0,1))) errors.rejectValue("birthday", "underage.birthday"); }
Example 13
Source File: CreateUserValidator.java From webcurator with Apache License 2.0 | 5 votes |
/** @see org.springframework.validation.Validator#validate(Object, Errors). */ public void validate(Object aCmd, Errors aErrors) { CreateUserCommand cmd = (CreateUserCommand) aCmd; ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_ACTION, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_ACTION), "Action command is a required field."); if (CreateUserCommand.ACTION_SAVE.equals(cmd.getAction())) { //If an Update or a Insert check the following ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_FIRSTNAME, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_FIRSTNAME), "Firstname is a required field."); ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_LASTNAME, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_LASTNAME), "Lastname is a required field."); ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_USERNAME, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_USERNAME), "Username is a required field."); ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_AGENCY_OID, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_AGENCY_OID), "Agency is a required field."); ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_EMAIL, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_EMAIL), "Email is a required field."); ValidatorUtil.validateStringMaxLength(aErrors, cmd.getAddress() ,200,"string.maxlength",getObjectArrayForLabelAndInt(CreateUserCommand.PARAM_ADDRESS,200),"Address field too long"); if (cmd.getEmail() != null && cmd.getEmail().length() > 0) { ValidatorUtil.validateRegEx(aErrors, cmd.getEmail(), ValidatorUtil.EMAIL_VALIDATION_REGEX, "invalid.email",getObjectArrayForLabel(CreateUserCommand.PARAM_EMAIL),"the email address is invalid" ); } if (cmd.getOid() == null) { //for a brand new user validate these things if (cmd.isExternalAuth() == false) { //Only check the password fields if not using an external Authentication Source ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_PASSWORD, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_PASSWORD), "Password is a required field."); ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateUserCommand.PARAM_CONFIRM_PASSWORD, "required", getObjectArrayForLabel(CreateUserCommand.PARAM_CONFIRM_PASSWORD), "Confirm password is a required field."); ValidatorUtil.validateValueMatch(aErrors, cmd.getPassword(), cmd.getConfirmPassword(), "string.match", getObjectArrayForTwoLabels(CreateUserCommand.PARAM_PASSWORD, CreateUserCommand.PARAM_CONFIRM_PASSWORD), "Your passwords did not match."); ValidatorUtil.validateNewPassword(aErrors,cmd.getPassword(),"password.strength.failure", new Object[] {}, "Your password must have at least 1 Upper case letter, 1 lower case letter and a number."); } } else { //for existing users validate these additional things } } }
Example 14
Source File: AssociateUsagePointController.java From OpenESPI-DataCustodian-java with Apache License 2.0 | 5 votes |
public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "UUID", "field.required", "UUID is required"); try { UsagePointForm form = (UsagePointForm) target; UUID.fromString(form.getUUID()); } catch (IllegalArgumentException x) { errors.rejectValue("UUID", "uuid.required", null, "Must be a valid UUID Ex. 550e8400-e29b-41d4-a716-446655440000"); } }
Example 15
Source File: TargetAnnotationValidator.java From webcurator with Apache License 2.0 | 5 votes |
public void validate(Object comm, Errors errors) { TargetAnnotationCommand command = (TargetAnnotationCommand) comm; if(command.isAction(TargetAnnotationCommand.ACTION_ADD_NOTE) || command.isAction(TargetAnnotationCommand.ACTION_MODIFY_NOTE)) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, TargetAnnotationCommand.PARAM_NOTE, "required", getObjectArrayForLabel(TargetAnnotationCommand.PARAM_NOTE), "Note is a required field"); ValidatorUtil.validateStringMaxLength(errors, command.getNote(), TargetAnnotationCommand.CNST_MAX_NOTE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(TargetAnnotationCommand.PARAM_NOTE, TargetAnnotationCommand.CNST_MAX_NOTE_LENGTH), "Annotation is too long"); } else { ValidatorUtil.validateStringMaxLength(errors, command.getEvaluationNote(), Target.MAX_EVALUATION_NOTE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(TargetAnnotationCommand.PARAM_EVALUATION_NOTE, Target.MAX_EVALUATION_NOTE_LENGTH), "Evaluation Note is too long"); ValidatorUtil.validateStringMaxLength(errors, command.getSelectionNote(), Target.MAX_SELECTION_NOTE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(TargetAnnotationCommand.PARAM_SELECTION_NOTE, Target.MAX_SELECTION_NOTE_LENGTH), "Selection Note is too long"); ValidatorUtil.validateStringMaxLength(errors, command.getSelectionType(), Target.MAX_SELECTION_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(TargetAnnotationCommand.PARAM_SELECTION_TYPE, Target.MAX_SELECTION_TYPE_LENGTH), "Selection Type is too long"); ValidatorUtil.validateStringMaxLength(errors, command.getSelectionType(), Target.MAX_SELECTION_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(TargetAnnotationCommand.PARAM_HARVEST_TYPE, Target.MAX_HARVEST_TYPE_LENGTH), "Harvest Type is too long"); } }
Example 16
Source File: LoginValidator.java From java-course-ee with MIT License | 4 votes |
public void validate(Object o, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.username.empty", "Please specify a username."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty", "Please specify a password."); }
Example 17
Source File: SuggestPodcastValidator.java From podcastpedia-web with MIT License | 4 votes |
public void validate(Object target, Errors errors) { SuggestedPodcast suggestedPodcast = (SuggestedPodcast)target; /* validate name */ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name"); /* validate identifier */ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "identifier", "required.identifier"); verifyIdentifier(errors, suggestedPodcast); /* validate feed */ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "feedUrl", "required.feedUrl"); /* validate email*/ if(!isEmailValid(suggestedPodcast.getEmail())){ errors.rejectValue("email", "invalid.required.email"); } /* validate suggested keywords */ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "suggestedTags", "required.keywords"); Pattern pattern = Pattern.compile(REGEX_COMMA_SEPARATED_WORDS, Pattern.UNICODE_CHARACTER_CLASS); Matcher matcher; matcher = pattern.matcher(suggestedPodcast.getSuggestedTags()); if( suggestedPodcast.getSuggestedTags() != null && (!matcher.matches() || suggestedPodcast.getSuggestedTags().length() > MAX_KEYWORDS_LENGTH)) { errors.rejectValue("suggestedTags", "invalid.suggestedTags"); } /* validate category */ if(suggestedPodcast.getCategories() == null){ errors.rejectValue("categories", "required.category"); } /* validate social fan pages */ if(isInvalidFacebookFanPageUrl(suggestedPodcast) ) { errors.rejectValue("facebookPage", "invalid.socialFanPage"); } if(isInvalidTwitterFanPageUrl(suggestedPodcast) ) { errors.rejectValue("twitterPage", "invalid.socialFanPage"); } if(isInvalidGPlusFanPageUrl(suggestedPodcast) ) { errors.rejectValue("gplusPage", "invalid.socialFanPage"); } }
Example 18
Source File: TestRunValidator.java From etf-webapp with European Union Public License 1.2 | 4 votes |
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "label", "l.enter.label", "Please enter a label!"); }
Example 19
Source File: EmpValidator.java From maven-framework-project with MIT License | 4 votes |
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "empname", "emp.empname.empty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "empaddress", "emp.empaddress.empty"); }
Example 20
Source File: QaTiSummaryController.java From webcurator with Apache License 2.0 | 2 votes |
private void validateschedule(TargetSchedulesCommand scheduleCommand, BindException errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "startDate", "", getObjectArrayForLabel(TargetInstanceSummaryCommand.PARAM_START_DATE), "From Date is a required field"); ValidatorUtil.validateStartBeforeOrEqualEndTime(errors, scheduleCommand.getStartDate(), scheduleCommand.getEndDate(), "time.range", getObjectArrayForTwoLabels(TargetInstanceSummaryCommand.PARAM_START_DATE, TargetInstanceSummaryCommand.PARAM_END_DATE), "The start time must be before the end time."); }