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, @Nullable Object[] errorArgs,
        @Nullable String defaultMessage) 

Source Link

Document

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

Usage

From source file:validation.FirstTimeValidator.java

@Override
public void validate(Object target, Errors errors) {
    //FirstTime f  = (FirstTime)target;
    ValidationUtils.rejectIfEmpty(errors, "password", "required", new Object[] { "Password" },
            "Password field is empty");
    ValidationUtils.rejectIfEmpty(errors, "confirmPassword", "required", new Object[] { "Confirm Password" });

    if (!errors.hasFieldErrors("password") && !errors.hasFieldErrors("confirmPassword")) {
        FirstTime firstTime = (FirstTime) target;
        if (!firstTime.getPassword().matches(firstTime.getConfirmPassword())) {
            errors.rejectValue("confirmPassword", "notmatching", "Passwords not matching");
        }/*w  w w  . j a v a  2  s .co m*/
    }

}

From source file:org.opentestsystem.authoring.testauth.validation.AbstractDomainValidator.java

protected void rejectIfEmpty(final Errors e, final String fieldName, final Object... errorArgs) {
    final String errorCode = getErrorMessageRoot() + fieldName + MSG_REQUIRED;
    ValidationUtils.rejectIfEmpty(e, fieldName, errorCode, errorArgs, errorCode);
}