com.gianburga.servicios.bean.validator.TecnicoValidator.java Source code

Java tutorial

Introduction

Here is the source code for com.gianburga.servicios.bean.validator.TecnicoValidator.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gianburga.servicios.bean.validator;

import com.gianburga.servicios.bean.Tecnico;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;

/**
 *
 * @author gianfranco
 */

public class TecnicoValidator implements Validator {

    @Override
    public boolean supports(Class<?> type) {
        return Tecnico.class.equals(type);

    }

    @Override
    public void validate(Object o, Errors errors) {
        Tecnico tecnico = (Tecnico) o;
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nombre", "error.tecnico.nombre",
                "Campo de nombre incorrecto");
        ValidationUtils.rejectIfEmpty(errors, "fechaNacimiento", "error.tecnico.fechaNacimiento",
                "Escriba una fecha de nacimiento");

    }

}