更改应用程序语言环境会更改所有用户(Vaadin) [英] Changing application locale makes changes to all users (Vaadin)

查看:79
本文介绍了更改应用程序语言环境会更改所有用户(Vaadin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当用户进入系统以本地化组件时,我设置了语言环境.最近,我正在做一个演示,并注意到该语言正在从英语转换为荷兰语,而没有明显的原因.事实证明,另一个人同时访问了演示服务器(托管在德语服务器中),该服务器将其设置为荷兰语,并且影响了我的英语演示,反之亦然.

In my application I set up the locale when the user get into the system to localize the components. Recently I was giving a demo and noticed that the language was switching from English to Dutch without apparent reason. It turned out that the demo server (hosted in a German server) was being accessed at the same time by another person that set it to Dutch and was affecting my English demo and viceversa.

我尝试用不同的浏览器在我的机器上尝试使用Chrome正常模式和隐身模式等来模拟不同的会话,并且出现了问题.关于如何处理/解决此问题的任何想法?我以为Vaadin已经自行处理了用户会话,但是似乎应用程序的变量是共享的?

I gave it a try on my machine with different browsers, using Chrome normal and incognito modes, etc to simulate different sessions and the issue is present. Any ideas on how to handle/fix this? I thought Vaadin already handled user sessions on its own but it seems that the application's variables are shared?

这是我在应用程序中所做的更改语言环境的操作:

Here's what I do in my application to change the locale:

@Override
    public void setLocale(Locale locale) {
        super.setLocale(locale);
        xerb = ResourceBundle.getBundle("com.bluecubs.xinco.messages.XincoMessages", getLocale());
}

然后,使用xerb资源包对UI进行国际化.我尝试不进行超级调用,但结果是一样的,就像xerb被各种会话修改并在它们之间共享一样.

Then the xerb resource bundle is used to internationalize the UI. I tried not doing the super call but the result is the same, as if xerb was being modified by various sessions and shared among them.

有什么想法吗?

在Vaadin论坛上的相同问题: https://vaadin.com/forum/-/message_boards/view_message/1091312

Same question on Vaadin's forum: https://vaadin.com/forum/-/message_boards/view_message/1091312

修改

使用ThreadLocal模式,我在获得每个实例时向其添加了输出,并且每个浏览器都看到了不同的实例. (即第一个浏览器为com.bluecubs.xinco.core.server.vaadin.Xinco@2114ed,第二个浏览器为com.bluecubs.xinco.core.server.vaadin.Xinco@fd68fe),因此我认为该模型已正确使用.可悲的是,我仍然看到相同的问题.

Using ThreadLocal pattern I added outputs to when each instance is obtained and I see different instances for each browser. (i.e. com.bluecubs.xinco.core.server.vaadin.Xinco@2114ed for the first one and com.bluecubs.xinco.core.server.vaadin.Xinco@fd68fe for the second browser) so I believe the model is used correctly. Sadly I still see the same issue.

推荐答案

尝试应用 ThreadLocal模式即可从应用程序中的其他控件访问Application实例.这样,每当您尝试获取一些特定于会话的信息时,它就会更加明确.在Vaadin应用程序中它也相当普遍,因此代码可能更具可读性.

Try to apply ThreadLocal pattern to access the Application instance from other controls in the app. This way, it's more explicit whenever you try to obtain some session-specific information. It's also quite widespread in Vaadin applications, so the code may be more readable.

通过将Application的字段作为外部侦听器的外部类将其间接传递给您的Application字段,可能导致难以检测到错误,因为可能难以确定创建控件的确切时间以及<当时引用了c2>.

Passing the reference to the fields of your Application indirectly by making it an outer class for anonymous listeners can lead to hard to detect bugs, because it can be difficult to work out the exact moment of creating the controls and what ResourceBundle was referenced at that very point.

这篇关于更改应用程序语言环境会更改所有用户(Vaadin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆