List of usage examples for org.springframework.validation ValidationUtils rejectIfEmpty
public static void rejectIfEmpty(Errors errors, String field, String errorCode)
From source file:org.codeqinvest.web.validation.ValidationHelper.java
/** * Validates if a given field is not empty and uses * default error message key when violated. */// w w w . j av a 2 s . c om public static void rejectIfEmpty(Errors errors, String field) { ValidationUtils.rejectIfEmpty(errors, field, FIELD_REQUIRED); }
From source file:br.com.alura.casadocodigo.validation.ProdutoValidation.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "titulo", "field.required"); ValidationUtils.rejectIfEmpty(errors, "descricao", "field.required"); Produto produto = (Produto) target;//www .ja v a2 s. c om if (produto.getPaginas() <= 0) { errors.rejectValue("paginas", "field.required"); } }
From source file:com.bugbusters.lajarus.validation.QuestValidator.java
@Override public void validate(Object o, Errors errors) { QuestEntity questEntity = (QuestEntity) o; ValidationUtils.rejectIfEmpty(errors, "name", "name.empty"); if (questEntity.getName().length() < 4 || questEntity.getName().length() > 50) { errors.rejectValue("name", "Size.quest.name", "Name must be 4-50 characters long"); }//from www .j a v a2 s .c o m if (questService.isThereQuestByName(questEntity.getName())) { errors.rejectValue("name", "Existed.quest.name", "This name of the quest exists"); } if (questEntity.getLongitude() == 0) { errors.rejectValue("Longitude", "Longitude.isNull", "Longitude can not be null"); } if (questEntity.getLatitude() == 0) { errors.rejectValue("Latitude", "Latitude.isNull", "Latitude can not be null"); } }
From source file:com.bugbusters.lajarus.validation.ItemValidator.java
@Override public void validate(Object o, Errors errors) { ItemEntity itemEntity = (ItemEntity) o; ValidationUtils.rejectIfEmpty(errors, "name", "name.empty"); if (itemEntity.getName().length() < 4 || itemEntity.getName().length() > 50) { errors.rejectValue("name", "Size.item.name", "Name must be 4-50 characters long"); }// www .j a va 2s.c o m if (itemService.isThereItemtByName(itemEntity.getName())) { errors.rejectValue("name", "Existed.item.name", "This name of the item exists"); } ValidationUtils.rejectIfEmpty(errors, "type", "type.empty"); if (itemEntity.getType().length() < 4 || itemEntity.getType().length() > 50) { errors.rejectValue("type", "Size.item.type", "Type must be 4-50 characters long"); } ValidationUtils.rejectIfEmpty(errors, "value", "value.empty"); if (itemEntity.getValue() < 0) { errors.rejectValue("value", "Negetive.value", "Value can not be negative"); } ValidationUtils.rejectIfEmpty(errors, "price", "price.empty"); if (itemEntity.getPrice() < 0) { errors.rejectValue("price", "Negetive.price", "Price can not be negative"); } }
From source file:CRM.Validation.InteractionsValidation.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "first_name", "interactions.first_name.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "last_name", "interactions.last_name.required"); ValidationUtils.rejectIfEmpty(errors, "status", "interactions.status.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "method_of_contact", "interactions.method_of_contact.required"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "interactions.email.required"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "interactions.phone.required"); ValidationUtils.rejectIfEmpty(errors, "notes", "interactions.notes.required"); interactions interactions = (interactions) target; if (interactions.getFirst_name().length() > 45) { errors.rejectValue("first_name", "interactions.first_name.length"); }/* w w w. ja v a 2 s.c o m*/ if (interactions.getLast_name().length() > 45) { errors.rejectValue("last_name", "interactions.last_name.length"); } if (interactions.getStatus().length() > 45) { errors.rejectValue("status", "interactions.status.length"); } if (interactions.getMethod_of_contact().length() > 45) { errors.rejectValue("method_of_contact", "interactions.method_of_contact.length"); } // if(interactions.getEmail().length() > 64) { // errors.rejectValue("email", "interactions.email.length"); // } // if(interactions.getPhone().length() > 16) { // errors.rejectValue("phone", "interactions.phone.length"); // } if (interactions.getFirst_name() != null && !interactions.getFirst_name().matches("^[A-Za-z]{2,45}$")) { errors.rejectValue("first_name", "interactions.first_name.pattern"); } if (interactions.getLast_name() != null && !interactions.getLast_name().matches("^[A-Za-z]{2,45}$")) { errors.rejectValue("last_name", "interactions.last_name.pattern"); } // if(interactions.getEmail() != null && !interactions.getEmail().matches("^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")) { // errors.rejectValue("email", "interactions.email.pattern"); // } // if(interactions.getPhone() != null && !interactions.getPhone().matches("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])?$")) { // errors.rejectValue("phone", "interactions.phone.pattern"); // } }
From source file:sample.propertyvalidation.SamplePropertiesValidator.java
@Override public void validate(Object o, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "host", "host.empty"); ValidationUtils.rejectIfEmpty(errors, "port", "port.empty"); SampleProperties properties = (SampleProperties) o; if (properties.getHost() != null && !this.pattern.matcher(properties.getHost()).matches()) { errors.rejectValue("host", "Invalid host"); }/*from w w w . j a v a2 s. c om*/ }
From source file:com.acc.validator.ReviewDataValidator.java
@Override public void validate(final Object target, final Errors errors) { ValidationUtils.rejectIfEmpty(errors, HEADLINE, "field.required"); ValidationUtils.rejectIfEmpty(errors, COMMENT, "field.required"); validateRating(errors);//from ww w.j a v a 2s .c om }
From source file:com.acc.validator.ProductDataValidator.java
@Override public void validate(final Object target, final Errors errors) { final ProductData product = (ProductData) target; ValidationUtils.rejectIfEmpty(errors, "code", "field.required"); try {//from w ww .j a va 2 s .c om errors.pushNestedPath("reviews"); if (product.getReviews() != null) { for (final ReviewData review : product.getReviews()) { ValidationUtils.invokeValidator(this.reviewValidator, review, errors); } } } finally { errors.popNestedPath(); } }
From source file:CRM.Validation.ClientsValidation.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "first_name", "clients.first_name.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "last_name", "clients.last_name.required"); ValidationUtils.rejectIfEmpty(errors, "address_1", "clients.address_1.required"); ValidationUtils.rejectIfEmpty(errors, "city", "clients.city.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "zip", "clients.zip.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "clients.phone.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "clients.email.required"); ValidationUtils.rejectIfEmpty(errors, "date_of_hire", "clients.date_of_hire"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "file_number", "clients.file_number.required"); ValidationUtils.rejectIfEmpty(errors, "status", "clients.status.required"); clients clients = (clients) target;// w w w. j av a 2s .c o m if (clients.getFirst_name().length() > 45) { errors.rejectValue("first_name", "clients.first_name.length"); } if (clients.getLast_name().length() > 45) { errors.rejectValue("last_name", "clients.last_name.length"); } if (clients.getAddress_1().length() > 128) { errors.rejectValue("address_1", "clients.address_1.length"); } if (clients.getAddress_2().length() > 128) { errors.rejectValue("address_2", "clients.address_2.length"); } if (clients.getAddress_3().length() > 128) { errors.rejectValue("address_3", "clients.address_3.length"); } if (clients.getCity().length() > 64) { errors.rejectValue("city", "clients.city.length"); } if (clients.getZip().length() > 16) { errors.rejectValue("zip", "clients.zip.length"); } if (clients.getPhone().length() > 16) { errors.rejectValue("phone", "clients.phone.length"); } if (clients.getFax().length() > 16) { errors.rejectValue("fax", "clients.fax.length"); } if (clients.getEmail().length() > 45) { errors.rejectValue("email", "clients.email.length"); } if (clients.getDate_of_hire().length() > 45) { errors.rejectValue("date_of_hire", "clients.date_of_hire.length"); } if (clients.getFile_number().length() > 45) { errors.rejectValue("file_number", "clients.file_number.length"); } if (clients.getStatus().length() > 45) { errors.rejectValue("status", "clients.status.length"); } if (clients.getFirst_name().matches("^[A-Za-z]{2,45}$/")) { errors.rejectValue("first_name", "clients.first_name.pattern"); } if (clients.getLast_name().matches("[^A-Za-z0-9_'-]{2,45}$/")) { errors.rejectValue("last_name", "clients.last_name.pattern"); } if (!clients.getAddress_1().matches( "\\d+[ ](?:[A-Za-z0-9.-]+[ ]?)+(?:Avenue|Lane|Road|Boulevard|Drive|Street|Ave|Dr|Rd|Blvd|Ln|St)\\.?")) { errors.rejectValue("address_1", "clients.address_1.pattern"); } if (!clients.getCity().matches("(?:[A-Z][a-z.-]+[ ]?)+")) { errors.rejectValue("city", "clients.city.pattern"); } if (clients.getZip() != null && !clients.getZip().matches("^\\b\\d{5}(?:-\\d{4})?\\b$")) { errors.rejectValue("zip", "clients.zip.pattern"); } if (!clients.getPhone().matches( "^(?:(?:\\+?1\\s*(?:[.-]\\s*)?)?(?:\\(\\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\\s*\\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\\s*(?:[.-]\\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\\s*(?:[.-]\\s*)?([0-9]{4})(?:\\s*(?:#|x\\.?|ext\\.?|extension)\\s*(\\d+))?$")) { errors.rejectValue("phone", "clients.phone.pattern"); } if (clients.getFax() != null && !clients.getFax().matches( "^(?:(?:\\+?1\\s*(?:[.-]\\s*)?)?(?:\\(\\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\\s*\\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\\s*(?:[.-]\\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\\s*(?:[.-]\\s*)?([0-9]{4})(?:\\s*(?:#|x\\.?|ext\\.?|extension)\\s*(\\d+))?$")) { errors.rejectValue("fax", "clients.fax.pattern"); } if (!clients.getEmail().matches( "^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")) { errors.rejectValue("email", "clients.email.pattern"); } // if (!clients.getDate_of_hire().matches("(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)")) { // errors.rejectValue("date_of_hire", "clients.date_of_hire.pattern"); // } }
From source file:org.openmrs.logic.token.TokenRegistrationValidator.java
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) */// ww w .j a v a 2 s . c om public void validate(Object obj, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "token", "error.null"); ValidationUtils.rejectIfEmpty(errors, "providerClassName", "error.null"); ValidationUtils.rejectIfEmpty(errors, "configuration", "error.null"); ValidationUtils.rejectIfEmpty(errors, "providerToken", "error.null"); }