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.roadrantz.mvc.RantValidator.java

public void validate(Object command, Errors errors) {
    Rant rant = (Rant) command;//from www. j a  v a  2s  .  c o  m

    ValidationUtils.rejectIfEmpty(errors, "vehicle.state", "required.state", "State is required.");

    ValidationUtils.rejectIfEmpty(errors, "vehicle.plateNumber", "required.plateNumber",
            "The license plate number is required.");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "rantText", "required.rantText",
            "You must enter some rant text.");

    validatePlateNumber(rant.getVehicle().getPlateNumber(), errors);
}

From source file:com.gianburga.servicios.bean.validator.TecnicoValidator.java

@Override
public void validate(Object o, Errors errors) {
    Tecnico tecnico = (Tecnico) o;//from   ww  w  .  j a  v  a 2s .  co m
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nombre", "error.tecnico.nombre",
            "Campo de nombre incorrecto");
    ValidationUtils.rejectIfEmpty(errors, "fechaNacimiento", "error.tecnico.fechaNacimiento",
            "Escriba una fecha de nacimiento");

}

From source file:com.jklas.sample.petclinic.validation.VisitValidator.java

public void validate(Object obj, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "description", "required", "required");
}

From source file:com.jklas.sample.petclinic.validation.OwnerValidator.java

public void validate(Object obj, Errors errors) {
    Owner owner = (Owner) obj;
    ValidationUtils.rejectIfEmpty(errors, "firstName", "required", "required");
    ValidationUtils.rejectIfEmpty(errors, "lastName", "required", "required");
    ValidationUtils.rejectIfEmpty(errors, "address", "required", "required");
    ValidationUtils.rejectIfEmpty(errors, "city", "required", "required");
    String telephone = owner.getTelephone();
    if (!StringUtils.hasLength(telephone)) {
        errors.rejectValue("telephone", "required", "required");
    } else {//from   w  ww.jav a  2 s. c om
        for (int i = 0; i < telephone.length(); ++i) {
            if ((Character.isDigit(telephone.charAt(i))) == false) {
                errors.rejectValue("telephone", "nonNumeric", "non-numeric");
                break;
            }
        }
    }
}

From source file:com.cognitivabrasil.repositorio.web.validators.UserEditValidator.java

@Override
public void validate(Object target, Errors errors) {
    super.validate(target, errors);

    UserDto u = (UserDto) target;/*  w  w w  . jav a 2s.co  m*/

    if (!(isBlank(u.getPassword()) && isBlank(u.getConfirmPass()))) {
        ValidationUtils.rejectIfEmpty(errors, "password", "required.password",
                "Informe uma senha de no mnimo 5 dgitos");
        ValidationUtils.rejectIfEmpty(errors, "confirmPass", "required.confirmPass", "Confirme a senha");
    }
}

From source file:org.zilverline.web.CollectionValidator.java

public void validate(Object obj, Errors errors) {
    FileSystemCollection collection = (FileSystemCollection) obj;
    ValidationUtils.rejectIfEmpty(errors, "name", "error.required", "required");
    ValidationUtils.rejectIfEmpty(errors, "contentDir", "error.required", "required");
    File thisFile = (File) errors.getFieldValue("contentDir");
    if (thisFile == null || !thisFile.isDirectory()) {
        errors.rejectValue("contentDir", "error.dirnoexist", "directory does not exist");
    }/*from  ww  w  .ja va 2s  .  co  m*/

}

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

public void validateAuthor(Book book, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "author", "book.author.required", "Author is required.");
}

From source file:com.cognitivabrasil.repositorio.web.validators.UserValidator.java

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

    ValidationUtils.rejectIfEmpty(errors, "name", "required.name", " necessrio informar um nome");
    ValidationUtils.rejectIfEmpty(errors, "username", "required.username", "Informar o login");
    ValidationUtils.rejectIfEmpty(errors, "role", "required.role", "Informar o tipo de usurio");

    UserDto u = (UserDto) target;//from   ww  w. j  a  v  a2  s. com

    if (u.getPassword() != null && !u.getPassword().equals(u.getConfirmPass())) {
        errors.rejectValue("confirmPass", "invalid.confirmPass", "As senhas no conferem");
    }

    if (!isBlank(u.getPassword()) && u.getPassword().length() < 5) {
        errors.rejectValue("password", "invalid.password", "Informe uma senha de no mnimo 5 dgitos");
    }

    //verifica se ja existe um usuario com o mesmo username
    User uTest = userService.get(u.getUsername());
    if (uTest != null && !uTest.getId().equals(u.getId())) {
        if (uTest.isDeleted()) {
            errors.rejectValue("username", "invalid.username",
                    "Existe usurio deletado com esse login, se desejar reativar entre na lista de usurios deletados.");
        } else {
            errors.rejectValue("username", "invalid.username",
                    "J existe um usurio cadastrado com esse login");
        }
    }
}

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

public void validateTitle(Book book, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "title", "book.title.required", "Title is required.");
}

From source file:org.opentides.web.validator.SystemCodesValidator.java

@Override
public void validate(Object target, Errors errors) {
    SystemCodes systemCodes = (SystemCodes) target;

    ValidationUtils.rejectIfEmpty(errors, "category", "error.required", new Object[] { "Category" });
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "key", "error.required", new Object[] { "Key" });
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "value", "error.required", new Object[] { "Value" });

    if (systemCodesService.isDuplicateKey(systemCodes)) {
        errors.reject("error.duplicate-key", new Object[] { "\"" + systemCodes.getKey() + "\"", "key" },
                "\"" + systemCodes.getKey() + "\" already exists. Please try a different key.");
    }//from w w w . j a v  a 2s  .  c  o  m

    if (!systemCodes.isParentValid()) {
        errors.reject("error.parent-invalid",
                new Object[] { "\"" + systemCodes.getKey() + "\"",
                        "\"" + systemCodes.getParent().getKey() + "\"" },
                "\"" + systemCodes.getKey() + "\" conflicts with \"" + systemCodes.getParent().getKey()
                        + "\". Please try a different one.");
    }

    if (!StringUtil.isEmpty(systemCodes.getParentString())) {
        SystemCodes parent = systemCodesService.findByKey(systemCodes.getParentString());
        if (parent == null) {
            errors.reject("error.parent-does-not-exist", new Object[] { systemCodes.getParentString() },
                    systemCodes.getParentString() + " does not exist, please choose a valid Parent.");
        }
    }

}