gwtinternationalizationgwt-validation

GWT validation framework, how to specify location of internationalization bundle


This one is related to my previous post. Is it possible in GWT validation framework to specify location of ValidationMessages.properties files and their names? I already have messages translations in my application and I'd prefer them to be in one location.


Solution

  • You could create a custom UserValidationMessagesResolver:

    public class CustomValidationMessagesResolver extends AbstractValidationMessageResolver implements UserValidationMessagesResolver {
        protected CustomValidationMessagesResolver() {
            super((ConstantsWithLookup) GWT.create(ValidationConstants.class));
        }
    }
    

    In the above code, ValidationConstants is the class resulting from running I18NSync on my properties file.

    Then in *.gwt.xml:

    <replace-with class="yourpackage.client.validation.CustomValidationMessagesResolver">
        <when-type-is class="com.google.gwt.validation.client.UserValidationMessagesResolver" />
    </replace-with>
    

    You can find a complete example here.