Java Code Examples for org.springframework.validation.ValidationUtils#rejectIfEmpty()

The following examples show how to use org.springframework.validation.ValidationUtils#rejectIfEmpty() . 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: PersonValidator.java    From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "name", "name.empty");

	List<Field> fileds = getFields(target.getClass());
	for (Field field : fileds) {
		Annotation[] annotations = field.getAnnotations();
		for (Annotation annotation : annotations) {
			if (annotation.annotationType().getAnnotation(Valid.class) != null) {
				try {
					ValidatorRule validatorRule = personValidatorConfig.findRule(annotation);
					if (validatorRule != null) {
						validatorRule.valid(annotation, target, field, errors);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
 
Example 2
Source File: OrderValidator.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void validateShippingAddress(Order order, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "shipToFirstName", "FIRST_NAME_REQUIRED", "Shipping Info: first name is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipToLastName", "LAST_NAME_REQUIRED", "Shipping Info: last name is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipAddress1", "ADDRESS_REQUIRED", "Shipping Info: address is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipCity", "CITY_REQUIRED", "Shipping Info: city is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipState", "STATE_REQUIRED", "Shipping Info: state is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipZip", "ZIP_REQUIRED", "Shipping Info: zip/postal code is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipCountry", "COUNTRY_REQUIRED", "Shipping Info: country is required.");
}
 
Example 3
Source File: OrderValidator.java    From cacheonix-core with GNU Lesser General Public License v2.1 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 4
Source File: TransferSeedsValidator.java    From webcurator with Apache License 2.0 5 votes vote down vote up
public void validate(Object aCommand, Errors aErrors) {
	TransferSeedsCommand command = (TransferSeedsCommand) aCommand;
	if(TransferSeedsCommand.ACTION_TRANSFER.equals(command.getActionCmd())) {
		ValidationUtils.rejectIfEmpty(aErrors, TransferSeedsCommand.PARAM_TO_PERMISSION_OID, "required", getObjectArrayForLabel(TransferSeedsCommand.PARAM_TO_PERMISSION_OID), "Target permission is required");
	}
	
}
 
Example 5
Source File: SignupController.java    From Spring-MVC-Blueprints with MIT License 5 votes vote down vote up
@RequestMapping(params = "action=signup")
public void action(ActionRequest request, ActionResponse response,
		LoginForm loginForm, Errors errors, SessionStatus sessionStatus) {
	ValidationUtils.rejectIfEmpty(errors, "firstName", "firstName.empty",
			"Please, fill in your first name");
	ValidationUtils.rejectIfEmpty(errors, "lastName", "lastName.empty",
			"Please, fill in your last name");
	if (!errors.hasErrors()) {
		response.setRenderParameter("action", "login");
	}
}
 
Example 6
Source File: AccountValidator.java    From jpetstore-kubernetes with Apache License 2.0 5 votes vote down vote up
public void validate(Object obj, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "firstName", "FIRST_NAME_REQUIRED", "First name is required.");
	ValidationUtils.rejectIfEmpty(errors, "lastName", "LAST_NAME_REQUIRED", "Last name is required.");
	ValidationUtils.rejectIfEmpty(errors, "email", "EMAIL_REQUIRED", "Email address is required.");
	ValidationUtils.rejectIfEmpty(errors, "phone", "PHONE_REQUIRED", "Phone number is required.");
	ValidationUtils.rejectIfEmpty(errors, "address1", "ADDRESS_REQUIRED", "Address (1) is required.");
	ValidationUtils.rejectIfEmpty(errors, "city", "CITY_REQUIRED", "City is required.");
	ValidationUtils.rejectIfEmpty(errors, "state", "STATE_REQUIRED", "State is required.");
	ValidationUtils.rejectIfEmpty(errors, "zip", "ZIP_REQUIRED", "ZIP is required.");
	ValidationUtils.rejectIfEmpty(errors, "country", "COUNTRY_REQUIRED", "Country is required.");
}
 
Example 7
Source File: OrderValidator.java    From jpetstore-kubernetes with Apache License 2.0 5 votes vote down vote up
public void validateShippingAddress(Order order, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "shipToFirstName", "FIRST_NAME_REQUIRED", "Shipping Info: first name is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipToLastName", "LAST_NAME_REQUIRED", "Shipping Info: last name is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipAddress1", "ADDRESS_REQUIRED", "Shipping Info: address is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipCity", "CITY_REQUIRED", "Shipping Info: city is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipState", "STATE_REQUIRED", "Shipping Info: state is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipZip", "ZIP_REQUIRED", "Shipping Info: zip/postal code is required.");
	ValidationUtils.rejectIfEmpty(errors, "shipCountry", "COUNTRY_REQUIRED", "Shipping Info: country is required.");
}
 
Example 8
Source File: OrderValidator.java    From jpetstore-kubernetes with 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 9
Source File: AccountFormController.java    From jpetstore-kubernetes with Apache License 2.0 5 votes vote down vote up
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 10
Source File: DepartmentValidator.java    From SA47 with 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 11
Source File: RoleValidator.java    From SA47 with 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 12
Source File: UserValidator.java    From SA47 with 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 13
Source File: StudentValidator.java    From SA47 with 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 14
Source File: PetValidator.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void validateSpecies(Pet pet, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "species", "SPECIES_REQUIRED", "Species is required.");
}
 
Example 15
Source File: OrderValidator.java    From jpetstore-kubernetes with Apache License 2.0 4 votes vote down vote up
public void validateCreditCard(Order order, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "creditCard", "CCN_REQUIRED", "FAKE (!) credit card number required.");
	ValidationUtils.rejectIfEmpty(errors, "expiryDate", "EXPIRY_DATE_REQUIRED", "Expiry date is required.");
	ValidationUtils.rejectIfEmpty(errors, "cardType", "CARD_TYPE_REQUIRED", "Card type is required.");
}
 
Example 16
Source File: UserCityNameNotEmptyValidator.java    From thinking-in-spring-boot-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "city.name", "","用户的城市名称不能为空");
}
 
Example 17
Source File: TransactionValidator.java    From cloudstreetmarket.com with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "quote", "transaction.quote.empty");
	ValidationUtils.rejectIfEmpty(errors, "user", "transaction.user.empty");
	ValidationUtils.rejectIfEmpty(errors, "type", "transaction.type.empty");
}
 
Example 18
Source File: PetValidator.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void validateBreed(Pet pet, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "breed", "BREED_REQUIRED", "Breed is required.");
}
 
Example 19
Source File: OrderValidator.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void validateCreditCard(Order order, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "creditCard", "CCN_REQUIRED", "FAKE (!) credit card number required.");
	ValidationUtils.rejectIfEmpty(errors, "expiryDate", "EXPIRY_DATE_REQUIRED", "Expiry date is required.");
	ValidationUtils.rejectIfEmpty(errors, "cardType", "CARD_TYPE_REQUIRED", "Card type is required.");
}
 
Example 20
Source File: PetValidator.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void validateBirthdate(Pet pet, Errors errors) {
	ValidationUtils.rejectIfEmpty(errors, "birthdate", "required.java.util.Date", "Birthdate is required.");
}