I was working on apache commons validator latest. Problem explained below.
My Bean is having 2 properties fullName (String) & age (int). Validation "required" on both but age needed to be checked for "integer" as well.
bean.setFullName("Tester"); -----> Will Pass
bean.setAge("Too Old"); ---> "required Pass but "integer" Fail.
results = validator.validate();
Note: Above is possible if age property is String but its not and setAge won't accept String value and throw exception before reaching validator.validate().
Validation should be checked before we set the bean. In above situation I need to make all properties string than in validation.xml check for integer/condition.
How I work with this when my age property is Integer. little confused. Handle bean with date, integer etc?
My Bean is having 2 properties fullName (String) & age (int). Validation "required" on both but age needed to be checked for "integer" as well.
If your domain class declares age
already to be an int
then you have two options
My recommendation
commons-validator only works on strings (if you want your entire bean to be validated at once) and isn't a fit for your scenario. I suggest you dump that in favor of the standard JSR 303. It is rich in functionality and has a two very good implementations: