FileDocCategorySizeDatePackage
BikeValidator.javaAPI DocExample949Sat Apr 23 19:42:28 BST 2005com.springbook

BikeValidator

public class BikeValidator extends Object implements org.springframework.validation.Validator

Fields Summary
Constructors Summary
Methods Summary
public booleansupports(java.lang.Class aClass)

        return aClass.equals(Bike.class);
    
public voidvalidate(java.lang.Object o, org.springframework.validation.Errors errors)

        Bike bike = (Bike)o;
        if(bike == null) {
            errors.rejectValue("manufacturer", "error.not-specified", null, "Value required.");
        } else {
            System.out.println("VALIDATOR: bike.manufacturer=" + bike.getManufacturer());
            if(bike.getManufacturer() == null || "".equals(bike.getManufacturer()))
                errors.rejectValue("manufacturer", "Value not present.", null, "Manufacturer required.");
            if(bike.getModel() == null || "".equals(bike.getModel()))
                errors.rejectValue("model", "Value not present.", null, "Model is required.");
        }