Example usage for org.springframework.validation ValidationUtils rejectIfEmpty

List of usage examples for org.springframework.validation ValidationUtils rejectIfEmpty

Introduction

In this page you can find the example usage for org.springframework.validation ValidationUtils rejectIfEmpty.

Prototype

public static void rejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs) 

Source Link

Document

Reject the given field with the given error code and error arguments if the value is empty.

Usage

From source file:com.opencredo.domain.BookValidator.java

public void validateCount(Book book, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "count", "book.count.required", "Current count is required.");
}

From source file:org.openmrs.module.metadatasharing.model.validator.SubscriptionHeaderValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should reject invalid package header
 * @should reject empty content URI//  www  .ja  v  a  2  s.  com
 */
@Override
public void validate(Object target, Errors errors) {
    SubscriptionHeader header = (SubscriptionHeader) target;
    errors.pushNestedPath("packageHeader");
    ValidationUtils.invokeValidator(packageValidator, header.getPackageHeader(), errors);
    errors.popNestedPath();

    ValidationUtils.rejectIfEmpty(errors, "contentUri",
            "metadatasharing.error.subscriptionHeader.contentUri.empty", "The contentUri cannot be empty");
}

From source file:com.epam.ta.reportportal.ws.validation.WidgetRQCustomValidator.java

@Override
public void validate(Object object, Errors errors, Object... validationHints) {
    if (isCheck(validationHints)) {
        ValidationUtils.rejectIfEmpty(errors, NAME, NOT_NULL, new Object[] { NAME });
        ValidationUtils.rejectIfEmpty(errors, CONTENT_PARAMETERS, NOT_NULL,
                new Object[] { CONTENT_PARAMETERS });
    }//from w  w w . j a v  a2s  . c o m

    // validate all not empty fields
    validator.validate(object, errors);
}

From source file:org.mifos.user.domain.UserDetailsValidator.java

/**
 * Simple password validation simply checks whether password is not blank.
 * TODO: strengthen password validation.
 * @param errors//ww w .  j ava  2s.com
 */
private void validatePassword(Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "password", "User.password.[not.blank]",
            "Password must be specified");
}

From source file:org.mifos.user.domain.UserDetailsValidator.java

private void validateId(String userId, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "userId", "User.userId[not.blank]", "User Id must not be missing");
    if (userDetailsManager.userExists(userId)) {
        errors.rejectValue("userId", "User.userId[not.exist]", "User id already exists.");
    }/*from w  w w  . jav  a 2s .c  o  m*/
}

From source file:com.epam.ta.reportportal.ws.validation.JaskonRequiredPropertiesValidator.java

@Override
public void validate(Object object, Errors errors) {
    for (Field field : collectFields(object.getClass())) {
        if (AnnotationUtils.isAnnotationDeclaredLocally(JsonInclude.class, field.getType())) {
            try {
                Object innerObject = Accessible.on(object).field(field).getValue();
                if (null != innerObject) {
                    errors.pushNestedPath(field.getName());
                    validate(innerObject, errors);
                }/* ww  w . ja  v a2s . c  o  m*/
            } catch (Exception e) {
                LOGGER.error("JaskonRequiredPropertiesValidator error: " + e.getMessage(), e);
                // do nothing
            }

        }
        if (field.isAnnotationPresent(JsonProperty.class)
                && field.getAnnotation(JsonProperty.class).required()) {
            String errorCode = new StringBuilder("NotNull.").append(field.getName()).toString();
            ValidationUtils.rejectIfEmpty(errors, field.getName(), errorCode, new Object[] { errorCode });
        }
    }
    if (errors.getNestedPath() != null && errors.getNestedPath().length() != 0) {
        errors.popNestedPath();
    }
}

From source file:org.jasig.portlet.test.mvc.tests.CookieTestController.java

/**
* Sets up a {@link Validator} for the forms in this {@link Controller}.
* @param binder/*  www  .ja  v a  2s  .  c  o m*/
*/
@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.setValidator(new Validator() {
        @Override
        public boolean supports(Class<?> clazz) {
            return CreateCookieFormBackingObject.class.equals(clazz);
        }

        @Override
        public void validate(Object target, Errors errors) {
            ValidationUtils.rejectIfEmpty(errors, "name", "name.empty", "name field cannot be empty");
            ValidationUtils.rejectIfEmpty(errors, "value", "value.empty", "value field cannot be empty");
        }
    });
}

From source file:edu.wisc.my.portlets.feedback.beans.FeedbackValidator.java

public void validate(Object command, Errors errors) {
    Feedback feedback = (Feedback) command;
    ValidationUtils.rejectIfEmpty(errors, "subject", "required.subject", "Subject is required");
    ValidationUtils.rejectIfEmpty(errors, "details", "required.details", "Feedback is required");
    validatePhone(feedback.getPhoneNumber(), errors);
    validateEmail(feedback.getEmailAddress(), errors);
    validateNetid(feedback.getNetid(), errors);

    // TODO check feedback substring call
    // TODO determine if this should be moved to the MessageFormatterImpl
    if (feedback.getSubject().length() >= MAX_SUBJECT_LENGTH) {
        feedback.setSubject(feedback.getSubject().substring(0, MAX_SUBJECT_LENGTH - 1));
    }/*ww  w.ja v a 2 s.co m*/
}

From source file:ca.uoguelph.ccs.portal.services.feedback.beans.FeedbackValidator.java

public void validate(Object command, Errors errors) {
    Feedback feedback = (Feedback) command;
    //ValidationUtils.rejectIfEmpty(errors, "subject", "required.subject", "Subject is required");
    //ValidationUtils.rejectIfEmpty(errors, "subject", "required.subject", "Channel is required");
    ValidationUtils.rejectIfEmpty(errors, "subject", "required.subject", "Subject is required");
    ValidationUtils.rejectIfEmpty(errors, "details", "required.details", "Feedback is required");
    validateEmail(feedback.getEmailAddress(), errors);

    // TODO check feedback substring call
    // TODO determine if this should be moved to the MessageFormatterImpl
    if (feedback.getSubject().length() >= MAX_SUBJECT_LENGTH) {
        feedback.setSubject(feedback.getSubject().substring(0, MAX_SUBJECT_LENGTH - 1));
    }// w  w w  .  jav a  2  s  .c om
}

From source file:edu.psu.citeseerx.myciteseer.domain.logic.CollectionValidator.java

public void validateName(Collection collection, Account account, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "name", "CNAME_REQUIRED", "A collection name is required.");

    if (myciteseer.getCollectionAlreadyExists(collection, account)) {
        errors.rejectValue("name", "NEW_CNAME_REQUIRED", "You already have a collection with this name.");
    }/*w w  w .  j a  v a2  s  .c  o m*/

    if (collection.getName().length() > MCSConstants.MAX_CNAME_LENGTH) {
        errors.rejectValue("name", "BAD_COLLECTION_NAME", "Supplied name is too long.");
    }
}