Hi again,
I'm having some problems with BeanValidator NOT looking up error message in the provided MessageSource. Section 16.2.3.3. "Localization" states that it is support as long as arguments are not used, but that might have been in another context. Section 16.2.1.1. "Rule Configuration" and Table 16.3 in the documentation (for 0.7) does not mention anything about error messages being resolved by MessageSource.
Does not BeanValidator support usage of MessageSource or am I missing out on something?
Also, can the MessageSource be fully qualified with package name (e.g. "se.stickybit.test.MyResourceBundle")?
The test below outputs:
ERROR COUNT: 1
Field error in object 'target' on field 'simple': rejected value [2short]; codes [SimpleBeanTest.SimpleBean.simple[length].target.simple,SimpleBeanTest.SimpleBean.simple[length].simple,SimpleBeanTest.SimpleBean.simple[length].java.lang.String,SimpleBeanTest.SimpleBean.simple[length]]; arguments [se.stickybit.test.rmiapi.beans.SimpleBeanTest$Simp leBean@b1c5fa,10,255]; default message [invalid_length]
simple
MyResourceBundle.properties:Code:public class SimpleBeanTest extends TestCase { public SimpleBeanTest(final String arg0) { super(arg0); } public void testValidation() throws Exception { SimpleBean sb = new SimpleBean(); sb.setSimple("2short"); GenericApplicationContext appCtx = new GenericApplicationContext(); ResourceBundleMessageSource rbms = new ResourceBundleMessageSource(); rbms.setAlwaysUseMessageFormat(true); rbms.setUseCodeAsDefaultMessage(false); rbms.setBasename("MyResourceBundle.properties"); appCtx.getBeanFactory().registerSingleton("messageSource", rbms); appCtx.refresh(); AnnotationBeanValidationConfigurationLoader l = new AnnotationBeanValidationConfigurationLoader(); l.setCheckValidatableAnnotation(true); l.setApplicationContext(appCtx); l.loadConfiguration(sb.getClass()); BeanValidator bv = new BeanValidator(); bv.setConfigurationLoader(l); // errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage()); // simple, SimpleBeanTest.SimpleBean.simple[length], [se.stickybit.test.beans.SimpleBeanTest$SimpleBean@d1e233, 10, 255], ) invalid_length BindException errors = new BindException(sb, "target"); bv.validate(sb, errors); assertEquals("Validation should fail with one (1) errors since length < 10 (0)", 1, errors.getErrorCount()); System.out.println("ERROR COUNT: " + errors.getErrorCount()); for (Object o : errors.getAllErrors()) { ObjectError oe = (ObjectError)o; System.out.println(oe.toString()); if (oe instanceof FieldError) { FieldError fieldError = (FieldError) oe; System.out.println(fieldError.getField()); } } } @Validatable public class SimpleBean { @Length(min = 10, max = 255, message ="invalid_length") //message = "feature name must be between 1-255 characters") private String simple; public void setSimple(String simple) { this.simple = simple; } public String getSimple() { return this.simple; } } }
Code:invalid_length=property has an invalid length


