/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package springvalidationtest;

import java.util.Date;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.validation.Validator;

/**
 *
 * @author dhaval
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        ApplicationContext ctx = new ClassPathXmlApplicationContext("/springvalidationtest/spring.xml");

        Employee e = new Employee();
        e.setId(1);
        e.setName("dhaval");
        e.setStatus("asdf");
        e.setBirthDate(new Date(90, 1, 1));
        
        Validator myValidator = (Validator) ctx.getBean("empValidator");
        BindException errors = new BindException(e, Employee.class.getName());
        myValidator.validate(e, errors);
        if (errors.hasErrors()){
            List<FieldError> err = errors.getFieldErrors();
            for(FieldError fe : err){
                System.out.println(fe.getDefaultMessage());
            }
        }

        System.out.println(e.getBirthDate());
    }

}
