Given a model class attribute that has e.g. @NotNull(message="my.message.key")
, does Vaadin support resolving that message key to an internationalized string when there are validation errors?
Digging through the source, the Vaadin BeanValidator class is ultimately instantiating its ValidatorFactory using Validation.buildDefaultValidatorFactory()
, instead of picking up the LocalValidatorFactoryBean
provided by Spring. Is this configurable somewhere?
Thanks, in the meantime Vaadin support had pointed me to https://github.com/vaadin/flow/issues/10000 as well, which you reported. The suggested approach works for ResourceBundles, but I need to fetch translations from a database source. I already have an I18NProvider doing this, would have liked to reuse it for the validation error messages.
You can create your own Message Interpolator that reads from the database
True but that class would be standalone and fully outside of any Spring managed functionality. I took another approach by modifying the BeanValidationBinder and BeanValidator classes to accept a ValidatorFactory, and then just pass it the LocalValidatorFactoryBean when instantiating.
You can always access spring beans
Via static accessors you mean, indeed it would be an option.
I think that BeanValidationBinder could easily accept a ValidatorFactory in a third constructor, and use that one to create the BeanValidator if present.