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.cilea.osd.jdyna.validator.SoggettarioValidator.java

public void validate(Object object, Errors errors) {
    log.debug("SoggettoValidator.java-----validate");
    Soggettario soggetto = (Soggettario) object;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nome", "error.message.fallita.campo.obbligatorio");
    validateVoce(soggetto, errors);//from   w  w  w . jav  a 2s .c o m
}

From source file:org.openmrs.module.appointmentscheduling.validator.AppointmentTypeValidator.java

/**
 * Checks the form object for any inconsistencies/errors
 * /*from  w  ww  .j  a  v  a2 s .  co  m*/
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if name is null or empty or whitespace
 * @should pass validation if all required fields have proper values
 */
public void validate(Object obj, Errors errors) {
    AppointmentType appointmentType = (AppointmentType) obj;
    if (appointmentType == null) {
        errors.rejectValue("appointmentType", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
        ValidationUtils.rejectIfEmpty(errors, "duration",
                "appointmentscheduling.AppointmentType.durationEmpty");
    }
}

From source file:edu.wisc.my.stats.web.command.validation.QueryCommandValidator.java

private void validateDates(QueryCommand queryCommand, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "queryParameters.start",
            "portlet.queryinfo.error.start.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "queryParameters.end",
            "portlet.queryinfo.error.end.required");

    final QueryParameters queryParameters = queryCommand.getQueryParameters();
    final Date start = queryParameters.getStart();
    final Date end = queryParameters.getEnd();
    if (start != null && end != null && start.after(end)) {
        errors.rejectValue("queryParameters.start", "portlet.queryinfo.error.start.greater_than_end");
    }//from   w w  w. j  a v a  2  s.  c  om
}

From source file:it.cilea.osd.jdyna.service.ValidatorClassificationService.java

public Errors validaNomeAlbero(DTOAlberoClassificatore albero, Errors errors) {
    if (applicationService.getAlberoByName(albero.getNome()) != null) {
        errors.rejectValue("nome", "error.albero.nome.esistente");
    }/*from   w  w  w .  j  a  va  2  s  .c  o m*/
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nome", "error.albero.nome.non.inserito");
    return errors;
}

From source file:org.openmrs.calculation.CalculationRegistrationValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 * @should fail if token registration name is not unique amongst all tokens
 * @should fail if token registration name is empty or whitespace
 * @should fail if token registration provider class name is empty or whitespace
 * @should fail if token registration calculation name is empty or whitespace
 * @should fail if token registration does not represent a valid calculation
 * @should pass valid token registration
 * @should pass existing token registration
 */// w  w  w .j a  v  a 2 s . c o  m
public void validate(Object obj, Errors errors) {
    CalculationRegistration target = (CalculationRegistration) obj;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "token", "error.null");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "providerClassName", "error.null");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "calculationName", "error.null");

    /* we need to check if this registration token has unique name amongst all registered tokens for each provider */
    if (StringUtils.isNotBlank(target.getToken())) {
        CalculationRegistrationService tokenService = Context.getService(CalculationRegistrationService.class);
        CalculationRegistration possibleDuplicate = tokenService
                .getCalculationRegistrationByToken(target.getToken());
        if (possibleDuplicate != null
                && !OpenmrsUtil.nullSafeEquals(possibleDuplicate.getId(), target.getId())) {
            errors.rejectValue("token", "calculation.CalculationRegistration.error.nonUniqueTokenName");
        }
    }
    try {
        CalculationUtil.getCalculationForCalculationRegistration(target);
    } catch (Exception e) {
        errors.reject(e.getMessage());
    }
}

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

private void doFurtherValidations(Object target, Errors errors) {
    if (errors.hasErrors()) {
        return;//from  w ww  .jav a 2s.  com
    }

    ExperienceModel experience = (ExperienceModel) target;
    if (!experience.isCurrent()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "monthTo", FIELD_MANDATORY);
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "yearTo", FIELD_MANDATORY);
        checkPeriodCorrectness(experience, errors);
    }
}

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

/**
 * Validates the object of the Province.
 *
 * @param target - Populated object of Province to validate
 * @param errors - Errors object that is building. May contain errors for the fields relating to types.
 *///from  w w w .  j a  va  2  s .  co m
public void validate(Object target, Errors errors) {

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, DESCRIPTION, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE);
    Province province = (Province) target;

    String validatorPattern = ValidatorExpressionUtil.getValidatorPattern("REFERENCE.PROVINCE.VALIDATOR");
    Pattern stringOnly = Pattern.compile(validatorPattern);
    String description = province.getDescription().trim();
    description = description.replaceAll(STRING_REGEX, STRING_SPACE);
    Matcher makeMatch = stringOnly.matcher(description);

    if (makeMatch.find()) {
        errors.rejectValue(DESCRIPTION, AkuraWebConstant.MISMATCH_ERROR);
    }
}

From source file:org.tonguetied.web.CountryValidator.java

/**
 * This validation method check if the all mandatory fields on a 
 * {@link Country} object have been set.
 * /*w ww .  j  a v  a 2 s. c  o m*/
 * @param country the {@link Country} object to validate
 * @param errors contextual state about the validation process (never null)
 */
private void validateMandatoryFields(final Country country, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_NAME, "error.country.name.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_CODE, "error.country.code.required");
}

From source file:org.pdfgal.pdfgalweb.validators.WatermarkValidator.java

@Override
public void validate(final Object target, final Errors errors) {

    final WatermarkForm watermarkForm = (WatermarkForm) target;

    // File validation
    final MultipartFile file = watermarkForm.getFile();
    this.validatorUtils.validateFile(file, errors, PDFEncryptionType.NON_ENCRYPTED);

    // Text validation
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "text", "common.validator.required");
    this.validateTextLenght(watermarkForm.getText(), watermarkForm.getWatermarkPosition(), file, errors);

    // Pages validation
    if (!this.validatorUtils.validateConcretePages(watermarkForm.getPages(), file, ",", "-", false, false)) {
        errors.rejectValue("pages", "watermark.validator.pages");
    }//from  w  w  w .jav  a2  s .  c  om
}

From source file:org.openmrs.module.radiology.order.web.DiscontinuationOrderRequestValidator.java

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 * @should fail validation if discontinuation order request is null
 * @should fail validation if orderer is null or empty or whitespaces only
 * @should fail validation if reason non coded is null or empty or whitespaces only
 * @should pass validation if all fields are correct
 */// www  .  j  a  v  a  2s  .  c  o m
@Override
public void validate(Object obj, Errors errors) {
    final DiscontinuationOrderRequest discontinuationOrderRequest = (DiscontinuationOrderRequest) obj;
    if (discontinuationOrderRequest == null) {
        errors.reject("error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "orderer", "error.null");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "reasonNonCoded", "error.null");
    }
}