@Override
    public void validate(Object obj, Errors errors) {
        Pet pet = (Pet) obj;
        String name = pet.getName();
        // name validation
        if (!StringUtils.hasLength(name)) {
            errors.rejectValue("name", REQUIRED, REQUIRED);
        }

        // type validation
        if (pet.isNew() && pet.getType() == null) {
            errors.rejectValue("type", REQUIRED, REQUIRED);
        }

        // birth date validation
        if (pet.getBirthDate() == null) {
            errors.rejectValue("birthDate", REQUIRED, REQUIRED);
        }
    }
<code>Validator</code> for <code>Pet</code> forms.
<p>
We're not using Bean Validation annotations here because it is easier to define such validation rule in Java.
</p>

@author Ken Krebs
@author Juergen Hoeller
src/main/java/org/springframework/samples/petclinic/web/PetValidator.java