Spring 3.1.1.RELEASE Databinding: error validating submitted form

Since upgrading my web application from Spring 3.0.5 to 3.1.1, I have encountered serious errors when validating my beans form. My previously configured validator does not work anymore as it should. The problem is that the getFieldValue method (string name of the string) from the class org.springframework.validation.Errors does not return the original bound value of the bean, as it should (as it was before).

Here is what my bean form looks like:

public class PersonBean extends BaseFormBean {

private String firstname; // getters and setter omitted...

    private String lastname; // getters and setter omitted...

    private Integer age; // getters and setter omitted...

    public PersonBean() {}

    @Override
    public void validateForm(Errors errors) {
        WebValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", "validator.requiredvalidator.lbl", "field required");
        WebValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", "validator.requiredvalidator.lbl", "field required");      
        WebValidationUtils.rejectInvalidIntValue(errors, "age", "validator.std.age", "invalid age", false);
    }
}

WebValidationUtils, , bean. , String, , Integer. Collection (s).

, Integer utils:

import org.springframework.validation.Errors;
...

public abstract class WebValidationUtils {
...
    public static void rejectInvalidIntValue(Errors errors, String field, String errorCode, String defaultMessage){
        Assert.notNull(errors, "Errors object must not be null");
        Object value = errors.getFieldValue(field); // returns the string value (type: java.lang.String)
                Class<?> fieldType = errors.getFieldType(field); // returns the class Integer!
        if (value == null || !value.getClass().equals(Integer.class) || ((Integer)value).intValue() <= 0){
                errors.rejectValue(field, errorCode, null, defaultMessage);
        }
    }
}

bean ...

additonal Spring beans -servlet.xml, bevahior, 3.0.5?

: Spring Doku getFieldValue (...)"

, bean, .

, , String bean Integer...

+3
1

, , getFieldValue() return FieldError.getFieldValue(), , . .

, , getRawFieldValue(). PropertyAccessor.

+1

All Articles