Example usage for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace

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

Introduction

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

Prototype

public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode) 

Source Link

Document

Reject the given field with the given error code if the value is empty or just contains whitespace.

Usage

From source file:it.f2informatica.core.validator.ConsultantEducationValidator.java

private void doFurtherValidations(Object target, Errors errors) {
    if (errors.hasErrors()) {
        return;/*from www . j  a  va 2  s  . co m*/
    }

    EducationModel education = (EducationModel) target;
    if (!education.isCurrent()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "endYear", FIELD_MANDATORY);
        if (!errors.hasErrors()) {
            checkPeriodCorrectness(education, errors);
        }
    }
}

From source file:org.openmrs.module.tribe.web.controller.TribeValidator.java

/**
 * /*  w  w w .ja  v a 2 s. c o  m*/
 * Checks the form object for any inconsistencies/errors
 * 
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
public void validate(Object obj, Errors errors) {
    Tribe tribe = (Tribe) obj;
    if (tribe == null) {
        errors.rejectValue("tribe", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
    }
}

From source file:org.training.storefront.forms.validation.PaymentDetailsValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final PaymentDetailsForm form = (PaymentDetailsForm) object;

    final Calendar start = parseDate(form.getStartMonth(), form.getStartYear());
    final Calendar expiration = parseDate(form.getExpiryMonth(), form.getExpiryYear());

    if (start != null && expiration != null && start.after(expiration)) {
        errors.rejectValue("startMonth", "payment.startDate.invalid");
    }//from   ww  w.  j ava  2s . c o  m

    final boolean editMode = StringUtils.isNotBlank(form.getPaymentId());
    if (editMode || Boolean.TRUE.equals(form.getNewBillingAddress())) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.titleCode", "address.title.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName",
                "address.firstName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName",
                "address.lastName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity",
                "address.townCity.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode",
                "address.postcode.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso",
                "address.country.invalid");
        // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line2", "address.line2.invalid"); // for some addresses this field is required by cybersource
    }
}

From source file:org.openmrs.web.controller.report.ReportValidator.java

/**
 * Checks the form object for any inconsistencies/errors
 * /*from   w ww. jav  a  2  s  .  c  o  m*/
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 */
public void validate(Object obj, Errors errors) {
    Report report = (Report) obj;
    if (report == null) {
        errors.rejectValue("report", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
    }
}

From source file:com.persistent.cloudninja.validator.CreateTaskListValidator.java

public void validate(Object target, Errors errors) {

    CreateManageListDTO createManageListDTO = (CreateManageListDTO) target;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.subject",
            "managetasklist.create.subject.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.startDate",
            "managetasklist.create.startdate.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.dueDate",
            "managetasklist.create.duedate.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.priority",
            "managetasklist.create.priority.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.details",
            "managetasklist.create.details.required");

    if (!DateValidator.isValidDate(createManageListDTO.getTaskList().getStartDate())) {
        errors.rejectValue("taskList.startDate", "Invalid Date", "Format is incorrect");
    } else if (!DateValidator.isValidDate(createManageListDTO.getTaskList().getDueDate())) {
        errors.rejectValue("taskList.dueDate", "Invalid Date", "Format is incorrect");
    } else if (!DateValidator.isValidDateRange(createManageListDTO.getTaskList().getStartDate(),
            createManageListDTO.getTaskList().getDueDate())) {

        errors.rejectValue("taskList.startDate", "Invalid Date",
                "Due Date is incorrect with respect to start date");

    }//from ww  w . j  a  v a  2 s . co  m
}

From source file:com.exxonmobile.ace.hybris.storefront.forms.validation.PaymentDetailsValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final PaymentDetailsForm form = (PaymentDetailsForm) object;

    final Calendar start = parseDate(form.getStartMonth(), form.getStartYear());
    final Calendar expiration = parseDate(form.getExpiryMonth(), form.getExpiryYear());

    if (start != null && expiration != null && start.after(expiration)) {
        errors.rejectValue("startMonth", "payment.startDate.invalid");
    }//from  w  ww.ja  va  2s  . c  o  m

    final boolean editMode = StringUtils.isNotBlank(form.getPaymentId());
    if (editMode || Boolean.TRUE.equals(form.getNewBillingAddress())) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.titleCode", "address.title.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName",
                "address.firstName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName",
                "address.lastName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity",
                "address.townCity.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode",
                "address.postcode.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso",
                "address.country.invalid");
        //         ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line2", "address.line2.invalid"); // for some addresses this field is required by cybersource
    }
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.forms.validation.PaymentDetailsValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final PaymentDetailsForm form = (PaymentDetailsForm) object;

    final Calendar start = CalendarHelper.parseDate(form.getStartMonth(), form.getStartYear());
    final Calendar expiration = CalendarHelper.parseDate(form.getExpiryMonth(), form.getExpiryYear());

    if (start != null && expiration != null && start.after(expiration)) {
        errors.rejectValue("startMonth", "payment.startDate.invalid");
    }/*  w w w .j  ava 2s. c o m*/

    final boolean editMode = StringUtils.isNotBlank(form.getPaymentId());
    if (editMode || Boolean.TRUE.equals(form.getNewBillingAddress())) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.titleCode", "address.title.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName",
                "address.firstName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName",
                "address.lastName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity",
                "address.townCity.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode",
                "address.postcode.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso",
                "address.country.invalid");
        // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line2", "address.line2.invalid"); // for some addresses this field is required by cybersource
    }
}

From source file:com.virtusa.akura.common.validator.NationalityValidator.java

/**
 * Validates the object of the Nationality.
 *
 * @param target - Populated object of Nationality to validate
 * @param errors - Errors object that is building. May contain errors for the fields relating to types.
 *//*  w w w .  ja  v a2 s.  c o  m*/
public void validate(Object target, Errors errors) {

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "REF.UI.NATIONALITY.DESCRIPTION.REQUIRED");
    Nationality nationality = (Nationality) target;

    String validatorPattern = ValidatorExpressionUtil.getValidatorPattern("REFERENCE.NATIONALITY.VALIDATOR");
    Pattern stringOnly = Pattern.compile(validatorPattern);
    String description = nationality.getDescription().trim();
    description = description.replaceAll("( )+", " ");
    Matcher makeMatch = stringOnly.matcher(description);
    if (makeMatch.find()) {
        errors.rejectValue("description", "REF.UI.FIELD.TYPE");
    }
}

From source file:org.openmrs.module.simpleservice.AwesomeLevelValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 *//*w  ww.  j a va  2 s . c  o m*/
public void validate(Object target, Errors errors) {
    // This first line makes sure the "level" attribute on the "target" object is filled in by the user

    // The last string is a messages.properties key code for translating into the user's current language.  
    // See both /metadata/messages.properties and /metadata/config.xml for the mapping
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "level", "simpleservice.levelCannotBeEmpty");

    // a custom validation on the given object
    AwesomeLevel levelObject = (AwesomeLevel) target;
    if (levelObject.getLevel() != null && levelObject.getLevel() < 5)
        errors.rejectValue("level", "simpleservice.levelCantBeThatLow");

}

From source file:com.virtusa.akura.common.validator.ExamSubjectValidator.java

/**
 * Validates objects of the ExamSubject.
 *
 * @param target - Populated object of ExamSubject to validate
 * @param errors - Errors object that is building. May contain errors for the fields relating to types.
 *//*  www  .j a v a2  s  .c o m*/
public void validate(Object target, Errors errors) {

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, EXAM_ID, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE);
    ExamSubject examSubject = (ExamSubject) target;
    if (examSubject.getExam().getExamId() == 0) {
        errors.rejectValue(EXAM_ID, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE);
    }
}