2013-05-02 143 views
2

也许这个问题被问到,但我找不到。我是Vaadin的新手。我如何设置Vaadin应用程序的默认区域设置。为Vaadin应用程序设置默认语言环境

+0

可能是这可以帮助:http://stackoverflow.com/questions/9023460/changing-application-locale-makes-changes-to-all-users-vaadin – 2013-05-02 05:49:01

回答

6

Vaadin 6:Application#setLocale(Locale)

Vaadin 7:VaadinSession#setLocale(Locale)例如VaadinSession.getCurrent().setLocale();

Vaadin 7的示例代码,可能在UI的init方法中使用。

Locale locale = Locale.CANADA_FRENCH; 
this.setLocale(locale); // Call to affect this current UI. Workaround for bug/issue: http://dev.vaadin.com/ticket/12350 
this.getSession().setLocale(locale); // Affects only future UI instances, not current one. See workaround in line above. 
// VaadinSession.getCurrent().setLocale(locale); // Alternative to "this.getSession". 
+0

这个答案我启发扩大Vaadin关于此主题的Wiki页面:[请记住设置语言环境](https://vaadin.com/wiki//wiki/Main/Remember+to+the+set+the+Locale)。我添加了示例代码和一些讨论。 – 2014-07-28 00:34:55

+0

请注意,Vaadin 7有严重的设计问题**(或错误)([ticket#12350](http://dev.vaadin.com/ticket/12350)),在VaadinSession上设置语言环境不会产生适当的效果在已经存在的UI对象中。解决方法很简单:[a]在当前UI上调用'setLocale'来影响它们,以及[b]在VaadinSession中调用'setLocale'来影响未来的UI对象。请参阅我上面评论中的维基链接,了解讨论和示例应用。 – 2014-07-28 01:55:36

相关问题