Java Code Examples for org.springframework.validation.ValidationUtils

The following examples show how to use org.springframework.validation.ValidationUtils. These examples are extracted from open source projects. 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 Project: Spring-MVC-Blueprints   Source File: IndexValidator.java    License: MIT License 7 votes vote down vote up
@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 Project: Spring-MVC-Blueprints   Source File: IndexValidator.java    License: MIT License 7 votes vote down vote up
@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 3
Source Project: registration-login-spring-hsql   Source File: UserValidator.java    License: MIT License 7 votes vote down vote up
@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 Project: webcurator   Source File: HarvestNowValidator.java    License: Apache License 2.0 7 votes vote down vote up
public void validate(Object aCommand, Errors aErrors) {
    TargetInstanceCommand cmd = (TargetInstanceCommand) aCommand;
    if (log.isDebugEnabled()) {
        log.debug("Validating harvest now target instance command.");
    }
    
    ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, TargetInstanceCommand.PARAM_CMD, "required", getObjectArrayForLabel(TargetInstanceCommand.PARAM_CMD), "Action command is a required field.");
    
    if (TargetInstanceCommand.ACTION_HARVEST.equals(cmd.getCmd())) {                        
        ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, TargetInstanceCommand.PARAM_AGENT, "required", getObjectArrayForLabel(TargetInstanceCommand.PARAM_AGENT), "Harvest agent is a required field.");
        ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, TargetInstanceCommand.PARAM_OID, "required", getObjectArrayForLabel(TargetInstanceCommand.PARAM_OID), "Target Instance Id is a required field.");
        if (!aErrors.hasErrors()) {                
            ValidatorUtil.validateMinimumBandwidthAvailable(aErrors, cmd.getTargetInstanceId(), "no.minimum.bandwidth", getObjectArrayForLabel(TargetInstanceCommand.PARAM_OID), "Adding this target instance will reduce the bandwidth.");
            if (cmd.getBandwidthPercent() != null) {                	
            	ValidatorUtil.validateMaxBandwidthPercentage(aErrors, cmd.getBandwidthPercent().intValue(), "max.bandwidth.exeeded");
            }                                            
        }
        
        if (!aErrors.hasErrors()) {
        	ValidatorUtil.validateTargetApproved(aErrors, cmd.getTargetInstanceId(), "target.not.approved");
        }
    }
}
 
Example 5
Source Project: yugastore-java   Source File: UserValidator.java    License: Apache License 2.0 6 votes vote down vote up
@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 6
Source Project: hellokoding-courses   Source File: UserValidator.java    License: MIT License 6 votes vote down vote up
@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 7
Source Project: hellokoding-courses   Source File: UserValidator.java    License: MIT License 6 votes vote down vote up
@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 8
@Override
public void validate(Object target, Errors errors) {
  ValidationUtils.rejectIfEmpty(errors, "req", "req.empty", "must have a req parameter");
  ValidationUtils.rejectIfEmpty(errors, "var", "var.empty", "data request must have a var paramater");

  CdmrFeatureQueryBean bean = (CdmrFeatureQueryBean) target;
  if (bean.getReq() == null)
    bean.addError("must have a req parameter");
  if (bean.getVar() == null)
    bean.addError("data request must have a var parameter");

  CdmrFeatureQueryBean.RequestType reqType;
  if (bean.getReq().equalsIgnoreCase("data"))
    reqType = CdmrFeatureQueryBean.RequestType.data;
  else if (bean.getReq().equalsIgnoreCase("header"))
    reqType = CdmrFeatureQueryBean.RequestType.header;
  else
    reqType = CdmrFeatureQueryBean.RequestType.data; // default

  bean.setReqType(reqType);
}
 
Example 9
@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 10
Source Project: springlets   Source File: CollectionValidator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validate each element inside the supplied {@link Collection}.
 * 
 * The supplied errors instance is used to report the validation errors.
 * 
 * @param target the collection that is to be validated
 * @param errors contextual state about the validation process
 */
@Override
@SuppressWarnings("rawtypes")
public void validate(Object target, Errors errors) {
  Collection collection = (Collection) target;
  int index = 0;

  for (Object object : collection) {
    BeanPropertyBindingResult elementErrors = new BeanPropertyBindingResult(object,
        errors.getObjectName());
    elementErrors.setNestedPath("[".concat(Integer.toString(index++)).concat("]."));
    ValidationUtils.invokeValidator(validator, object, elementErrors);

    errors.addAllErrors(elementErrors);
  }
}
 
Example 11
@Override
public void validate(Object obj, Errors errors) {
	SurveyPage surveyPage= (SurveyPage) obj;
	
	QuestionAnswerValidator questionAnswerValidator;
	int i = 0;
	for (QuestionAnswer questionAnswer : surveyPage.getQuestionAnswers()) {
		log.info("Validating question answer" +  questionAnswer.getQuestion().getQuestionText());
		errors.pushNestedPath("questionAnswers[" + i +"]");
		questionAnswerValidator = new QuestionAnswerValidator(dateFormat,
																validcontentTypes,
																validImageTypes,
																maximunFileSize,
																invalidContentMessage,
																invalidFileSizeMessage);
		ValidationUtils.invokeValidator(questionAnswerValidator, questionAnswer, errors);
		errors.popNestedPath();
		i++;
	}
}
 
Example 12
@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 13
Source Project: example-restful-project   Source File: TeapotValidator.java    License: MIT License 6 votes vote down vote up
/**
 * 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 14
Source Project: webcurator   Source File: TargetGeneralValidator.java    License: Apache License 2.0 6 votes vote down vote up
public void validate(Object comm, Errors errors) {
	TargetGeneralCommand command = (TargetGeneralCommand) comm;
	
	// Name is required and must be less than 50 characters.
	if(command.getName() != null) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", getObjectArrayForLabel(TargetGeneralCommand.PARAM_NAME), "Name is a required field");
		ValidatorUtil.validateStringMaxLength(errors, command.getName(), Target.MAX_NAME_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(TargetGeneralCommand.PARAM_NAME, Target.MAX_NAME_LENGTH), "Name is too long");
	}
	
	// Description must be less than 255 characters.
	if(command.getDescription() != null) {
		ValidatorUtil.validateStringMaxLength(errors, command.getDescription(), Target.MAX_DESC_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(TargetGeneralCommand.PARAM_DESCRIPTION, Target.MAX_DESC_LENGTH), "Description is too long");
	}
	
	if(command.getState() == -1) { 
		errors.reject("target.bad_state");
	}
}
 
Example 15
Source Project: webcurator   Source File: SiteURLsValidator.java    License: Apache License 2.0 6 votes vote down vote up
public void validate(Object aCmd, Errors aErrors) {
	UrlCommand cmd = (UrlCommand) aCmd;
	
	if (UrlCommand.ACTION_ADD_URL.equals(cmd.getActionCmd())) {		
		ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, "url", "required", new Object[] {"URL"}, "URL is a required field.");
		
		if (!aErrors.hasErrors()) {
			ValidatorUtil.validateURL(aErrors, cmd.getUrl(), "invalid.url", new Object[] { cmd.getUrl()}, "The URL provided is not valid");
		}			
		
		if (!aErrors.hasErrors()) {
			String url = cmd.getUrl();
			
			if (!strategy.isValidPattern(url)) {				
				aErrors.reject("invalid.url", new Object[] {cmd.getUrl()}, "The url provided is not valid.");
			}
		}
	}
}
 
Example 16
Source Project: webcurator   Source File: AgencyValidator.java    License: Apache License 2.0 6 votes vote down vote up
/** @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 17
Source Project: webcurator   Source File: CreateQaIndicatorValidator.java    License: Apache License 2.0 6 votes vote down vote up
/** @see org.springframework.validation.Validator#validate(Object, Errors). */
public void validate(Object aCmd, Errors aErrors) {
    CreateQaIndicatorCommand cmd = (CreateQaIndicatorCommand) aCmd;
    
    // protect the action
    ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateQaIndicatorCommand.PARAM_ACTION, "required", getObjectArrayForLabel(CreateQaIndicatorCommand.PARAM_ACTION), "Action command is a required field.");  
            
    // validate the remaining form fields
    if (CreateQaIndicatorCommand.ACTION_SAVE.equals(cmd.getAction())) {
        //If an Update or a Insert check the following
        ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateQaIndicatorCommand.PARAM_NAME, "required", getObjectArrayForLabel(CreateQaIndicatorCommand.PARAM_NAME), "Name is a required field.");
        ValidationUtils.rejectIfEmptyOrWhitespace(aErrors, CreateQaIndicatorCommand.PARAM_AGENCY_OID, "required", getObjectArrayForLabel(CreateQaIndicatorCommand.PARAM_AGENCY_OID), "Agency is a required field.");
        ValidatorUtil.validateStringMaxLength(aErrors, cmd.getName() ,100,"string.maxlength",getObjectArrayForLabelAndInt(CreateQaIndicatorCommand.PARAM_NAME,100),"Name field too long");
      
    }
}
 
Example 18
Source Project: webcurator   Source File: LogReaderValidator.java    License: Apache License 2.0 6 votes vote down vote up
public void validate(Object comm, Errors errors) {
	LogReaderCommand command = (LogReaderCommand) comm;

	ValidationUtils.rejectIfEmptyOrWhitespace(errors, LogReaderCommand.PARAM_LINES, "required", getObjectArrayForLabel(LogReaderCommand.PARAM_LINES), "Number of Lines is a required field");
	ValidatorUtil.validateRegEx(errors, command.getNoOfLines(), "^[0-9]*$", "typeMismatch.java.lang.Integer",getObjectArrayForLabel(LogReaderCommand.PARAM_LINES),"Number of Lines must be an integer");
	
	if(LogReaderCommand.VALUE_FROM_LINE.equals(command.getFilterType())) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, LogReaderCommand.PARAM_FILTER, "required", getObjectArrayForLabel(LogReaderCommand.PARAM_FILTER), "Line Number is a required field");
		ValidatorUtil.validateRegEx(errors, command.getFilter(), "^[0-9]*$", "typeMismatch.java.lang.Integer",getObjectArrayForLabel(LogReaderCommand.PARAM_FILTER),"Line Number must be an integer");
	}
	if(LogReaderCommand.VALUE_TIMESTAMP.equals(command.getFilterType())) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, LogReaderCommand.PARAM_FILTER, "required", getObjectArrayForLabel(LogReaderCommand.PARAM_FILTER), "Date/Time is a required field");
	}
	if(LogReaderCommand.VALUE_REGEX_MATCH.equals(command.getFilterType()) ||
			LogReaderCommand.VALUE_REGEX_CONTAIN.equals(command.getFilterType()) ||
			LogReaderCommand.VALUE_REGEX_INDENT.equals(command.getFilterType()) ) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, LogReaderCommand.PARAM_FILTER, "required", getObjectArrayForLabel(LogReaderCommand.PARAM_FILTER), "Regular Expression is a required field");
	}
}
 
Example 19
Source Project: webcurator   Source File: TargetSeedsValidator.java    License: Apache License 2.0 6 votes vote down vote up
public void validate(Object comm, Errors errors) {
	SeedsCommand command = (SeedsCommand) comm;
	
	// Linking new seeds.
	if(command.isAction(SeedsCommand.ACTION_LINK_NEW_CONFIRM)) {
		if(command.getLinkPermIdentity() == null ||
		   command.getLinkPermIdentity().length == 0) {
			errors.reject("target.errors.link.noneselected");
		}
	}
	
	// Adding seeds.
	if(command.isAction(SeedsCommand.ACTION_ADD)) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "seed", "required", getObjectArrayForLabel("seed"), "Seed is a required field");
		
           if (command.getSeed() != null && command.getSeed().length() > 0) {
               ValidatorUtil.validateURL(errors, command.getSeed(), "target.errors.badUrl", getObjectArrayForLabel("seed"),"Invalid URL");
           }
	}
	
	// Searching for Permissions
	if( command.isAction(SeedsCommand.ACTION_LINK_NEW_SEARCH)) {
		validateLinkSearch(command, errors);
	}
}
 
Example 20
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 21
@Override
public void validate(Object o, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "host", "host.empty");
    ValidationUtils.rejectIfEmpty(errors, "port", "port.empty");
    ValidatedProperties properties = (ValidatedProperties) o;

    if (properties.getHost() != null && !this.pattern.matcher(properties.getHost()).matches()) {
        errors.rejectValue("host", "Invalid host");
    }
}
 
Example 22
Source Project: SA47   Source File: StudentValidator.java    License: The Unlicense 5 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
	// TODO Auto-generated method stub
	Student s = (Student) target;
	ValidationUtils.rejectIfEmpty(errors, "nric", "NRIC can be empty");
	ValidationUtils.rejectIfEmpty(errors, "name", "Name cant be empty");
    System.out.println(s.toString());

}
 
Example 23
Source Project: SA47   Source File: UserValidator.java    License: The Unlicense 5 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
	User u = (User) target;
	ValidationUtils.rejectIfEmpty(errors, "userId", "error.user.userid.empty");
	ValidationUtils.rejectIfEmpty(errors, "employeeId", "error.user.employeeid.empty");
	ValidationUtils.rejectIfEmpty(errors, "name", "error.user.name.empty");
	ValidationUtils.rejectIfEmpty(errors, "password", "error.user.password.empty");
	System.out.println(u.toString());
}
 
Example 24
Source Project: SA47   Source File: CourseValidator.java    License: The Unlicense 5 votes vote down vote up
@Override
public void validate(Object arg0, Errors arg1) {
	Course course = (Course) arg0;	
	if ((course.getFromDate()!=null && course.getToDate()!=null)&&(course.getFromDate().compareTo(course.getToDate()) > 0)) {
		arg1.reject("toDate", "End date should be greater than start date.");
		arg1.rejectValue("toDate", "error.dates", "to date must be > from date");

	}
	ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "courseName", "error.courseName", "Course name is required.");
	ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "fromDate", "error.fromDate", "From Date is required.");
	ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "toDate", "error.toDate", "To Date is required.");
}
 
Example 25
Source Project: SA47   Source File: RoleValidator.java    License: The Unlicense 5 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
	Role r = (Role) target;
	ValidationUtils.rejectIfEmpty(errors, "roleId", "error.role.roleid.empty");
	ValidationUtils.rejectIfEmpty(errors, "name", "error.role.name.empty");
	ValidationUtils.rejectIfEmpty(errors, "description", "error.role.description.empty");
	System.out.println(r.toString());
}
 
Example 26
Source Project: SA47   Source File: DepartmentValidator.java    License: The Unlicense 5 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
	Department d = (Department) target;
	ValidationUtils.rejectIfEmpty(errors, "departmentId", "error.department.departmentId.empty");
	ValidationUtils.rejectIfEmpty(errors, "managerInCharge", "error.department.managerInCharge.empty");
    System.out.println(d.toString());
}
 
Example 27
Source Project: SA47   Source File: EmployeeValidator.java    License: The Unlicense 5 votes vote down vote up
@Override
public void validate(Object arg0, Errors arg1) {
	Employee employee = (Employee) arg0;
	ValidationUtils.rejectIfEmpty(arg1, "employeeId", "error.employee.employeeid.empty");
	//ValidationUtils.rejectIfEmpty(arg1, "managerId", "error.employee.managerid.empty");
	ValidationUtils.rejectIfEmpty(arg1, "name", "error.employee.name.empty");
	System.out.println(employee.toString());
}
 
Example 28
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors)
	throws Exception {

AccountForm accountForm = (AccountForm) command;
Account account = accountForm.getAccount();

if (request.getParameter("account.listOption") == null) {
	account.setListOption(false);
}
if (request.getParameter("account.bannerOption") == null) {
	account.setBannerOption(false);
}

errors.setNestedPath("account");
getValidator().validate(account, errors);
errors.setNestedPath("");

if (accountForm.isNewAccount()) {
	account.setStatus("OK");
	ValidationUtils.rejectIfEmpty(errors, "account.username", "USER_ID_REQUIRED", "User ID is required.");
	if (account.getPassword() == null || account.getPassword().length() < 1 ||
			!account.getPassword().equals(accountForm.getRepeatedPassword())) {
	 errors.reject("PASSWORD_MISMATCH",
			 "Passwords did not match or were not provided. Matching passwords are required.");
	}
}
else if (account.getPassword() != null && account.getPassword().length() > 0) {
  if (!account.getPassword().equals(accountForm.getRepeatedPassword())) {
		errors.reject("PASSWORD_MISMATCH",
				"Passwords did not match. Matching passwords are required.");
  }
 }
}
 
Example 29
Source Project: jpetstore-kubernetes   Source File: OrderValidator.java    License: Apache License 2.0 5 votes vote down vote up
public void validateBillingAddress(Order order, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "billToFirstName", "FIRST_NAME_REQUIRED", "Billing Info: first name is required.");
	ValidationUtils.rejectIfEmpty(errors, "billToLastName", "LAST_NAME_REQUIRED", "Billing Info: last name is required.");
	ValidationUtils.rejectIfEmpty(errors, "billAddress1", "ADDRESS_REQUIRED", "Billing Info: address is required.");
	ValidationUtils.rejectIfEmpty(errors, "billCity", "CITY_REQUIRED", "Billing Info: city is required.");
	ValidationUtils.rejectIfEmpty(errors, "billState", "STATE_REQUIRED", "Billing Info: state is required.");
	ValidationUtils.rejectIfEmpty(errors, "billZip", "ZIP_REQUIRED", "Billing Info: zip/postal code is required.");
	ValidationUtils.rejectIfEmpty(errors, "billCountry", "COUNTRY_REQUIRED", "Billing Info: country is required.");
}
 
Example 30
Source Project: java-course-ee   Source File: UserValidator.java    License: MIT License 5 votes vote down vote up
public void validate(Object o, Errors errors) {
    User user = (User) o;
    if (user == null) errors.reject("Null data received");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "login", "login.empty", "Login is reqired!");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "email.empty", "Email is reqired!");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.empty", "Password is reqired!");

}