When the RequestFactory validates my domain objects using a jsr303 validator it gets localized contraint violation message and a message key. I debuged the code and on the server side the default locale is used no matter what locale is used on the client side. I did not find any locale settings in the payload either.
Are there any examples how to treat localization in comibation with RequestFactory and BeanValidation? Should the messages be translated on the client or server side? What are the best practices?
Thanks!
I did not find any blue print to this problem so I implemented my own mechanisem. I added the currently selected language as an attribute to the header and on the server side I read the language from the header.
Client side:
MyRequestFactory factory = GWT.create(MyRequestFactory.class);
factory.initialize(new SimpleEventBus(), new DefaultRequestTransport() {
@Override
protected void configureRequestBuilder(RequestBuilder builder) {
super.configureRequestBuilder(builder);
builder.setHeader("X-GWT-Language",
LocaleInfo.getCurrentLocale().getLocaleName());
}
});
Server side (Grails):
def index = {
String gwtLanguage = request.getHeader("X-GWT-Language")
if(gwtLanguage){
Locale gwtLocale = new Locale(gwtLanguage)
RequestContextUtils.getLocaleResolver(request).setLocale(request, response, gwtLocale)
}
// ... Handle the RequestFactory request