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

Source Link

Document

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

Usage

From source file:commun.ExperienceValidator.java

@Override
public void validate(Object o, Errors errors) {
    ExperienceEntity e = (ExperienceEntity) o;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "NotEmpty.newExperience.description",
            "Can not be empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "NotEmpty.newExperience.title",
            "Can not be empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "localisation.city",
            "NotEmpty.newExperience.localisation.city", "Can not be empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "localisation.stat",
            "NotEmpty.newExperience.localisation.stat", "Can not be empty");

    if (e.getLocalisation().getZipcode() != null) {
        String zipcode = String.valueOf(e.getLocalisation().getZipcode());
        if (!validZipCode(zipcode)) {
            errors.rejectValue("localisation.zipcode", "Pattern.newExperience.localisation.zipcode",
                    "5 characters");
        }//from w w w .  j a v  a 2s .  c  o  m
    }
}

From source file:com.stormpath.tooter.validator.ChangePasswordValidator.java

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

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "change.password.required.password",
            "Field password is required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "confirmPassword",
            "change.password.required.confirm.password", "Field confirm password is required");

    User customer = (User) o;//from  ww  w  .j av a 2  s  .  c om

    if (!customer.getPassword().equals(customer.getConfirmPassword())) {
        errors.rejectValue("password", "password.not.match");
    }
}

From source file:com.stormpath.tooter.validator.SignUpValidator.java

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

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "signUp.required.firstName",
            "Field first name is required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "singUp.required.password",
            "Field password is required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "signUp.required.lastName",
            "Field last name is required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "signUp.required.email",
            "Field email is required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "confirmPassword", "signUp.required.confirm.password",
            "Field confirm password is required");

    User customer = (User) o;//w ww .j  ava 2 s . co m

    if (!customer.getPassword().equals(customer.getConfirmPassword())) {
        errors.rejectValue("password", "password.not.match");
    }
}

From source file:org.dspace.app.webui.cris.validator.WSValidator.java

public void validate(Object arg0, Errors arg1) {
    User ws = (User) arg0;/*from w ww  .  j av a2  s  .  co m*/

    if (ws.getTypeDef().equals(User.TYPENORMAL)) {
        ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "normalAuth.username",
                "error.form.ws.username.mandatory", "Username is mandatory");
        ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "normalAuth.password",
                "error.form.ws.password.mandatory", "Password is mandatory");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "specialAuth.token", "error.form.ws.token.mandatory",
                "Token is mandatory");
        ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "specialAuth.fromIP", "error.form.ws.fromip.mandatory",
                "Single IP is mandatory");

        Long froms = null;
        Long tos = null;
        if (ws.getFromIP() != null && !ws.getFromIP().isEmpty()) {
            if (!validator.isValidInet4Address(ws.getFromIP())) {
                arg1.reject("specialAuth.fromIP", "from IP not well formed");
            } else {
                try {
                    froms = AddressUtils.ipToLong(InetAddress.getByName(ws.getFromIP()));
                } catch (UnknownHostException e) {
                    arg1.reject("specialAuth.fromIP", "Unknown host exception");
                }
            }

            if (ws.getToIP() != null && !ws.getToIP().isEmpty()) {
                if (!validator.isValidInet4Address(ws.getToIP())) {
                    arg1.reject("specialAuth.ToIP", "to IP not well formed");
                } else {
                    try {
                        tos = AddressUtils.ipToLong(InetAddress.getByName(ws.getToIP()));

                    } catch (UnknownHostException e) {
                        arg1.reject("specialAuth.toIP", "Unknown host exception");
                    }
                }
            }

            if (froms != null && tos != null) {

                if (froms >= tos) {
                    arg1.reject("specialAuth.toIP", "Range not well formed");
                }

            }
        }

    }

}

From source file:net.maritimecloud.identityregistry.validators.VesselAttributeValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "attributeName", "attributeName.empty",
            "attributeName must not be empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "attributeValue", "attributeValue.empty",
            "attributeValue must not be empty");
    VesselAttribute vesselAttribute = (VesselAttribute) target;
    if (vesselAttribute.getAttributeName() != null && !Arrays
            .asList("imo-number", "mmsi-number", "callsign", "flagstate", "ais-class", "port-of-register")
            .contains(vesselAttribute.getAttributeName())) {
        errors.rejectValue("attributeName", "illegal.value", "attributeName value is invalid");
    }//from  w w  w .jav  a  2 s.com
}

From source file:com.sws.platform.mobile.security.controller.LoginValidator.java

public void validate(Object o, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.username.empty",
            "Please specify a username.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty",
            "Please specify a password.");
}

From source file:org.apigw.authserver.web.validator.DeveloperValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "required", "E-mail required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phoneNumber", "required", "Phone number required");
}

From source file:org.apigw.authserver.web.validator.ApplicationValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", "Name required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "required", "Description required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "clientId", "required", "ClientId required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "tags", "required", "Tags required");
    //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "organization", "required", "Organization required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "organizationNumber", "required",
            "Organization number required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "required", "E-mail required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phonenumber", "required", "Phone number required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "url", "required", "URL required");

}

From source file:org.xinta.eazycode.components.shiro.web.validator.LoginValidator.java

public void validate(Object o, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginName", "error.username.empty",
            "Please specify a loginName.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty",
            "Please specify a password.");
}

From source file:net.maritimecloud.identityregistry.validators.VesselValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mrn", "mrn.empty", "mrn  is required.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "name.empty", "name is required.");
    Vessel vessel = (Vessel) target;/*w ww.  j a  v a 2  s .c o  m*/
    if (vessel.getAttributes() != null) {
        for (int i = 0; i < vessel.getAttributes().size(); ++i) {
            try {
                errors.pushNestedPath("attributes[" + i + "]");
                ValidationUtils.invokeValidator(this.vesselAttributeValidator, vessel.getAttributes().get(i),
                        errors);
            } finally {
                errors.popNestedPath();
            }
        }
    }
}