语言环境的本机选择

语言环境的本机选择

本文介绍了Vaadin 语言环境的本机选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Vaadin.我想使用 Native Select 在语言环境之间切换.

I'm using Vaadin. I want to use Native Select to switch between locales.

@Override
public void valueChange(ValueChangeEvent event) {
    UI.getCurrent().setLocale(loc);
}

我想使用 event.getProperty() 但loc"必须是 Locale 类型.如何获取本机选择的值并将其转换为 Locale 类型?

I wanted to use event.getProperty() but "loc" have to be Locale type. How can i get value of native select and convert it into Locale type?

推荐答案

我猜你会像这样填充 NativeSelect :

I would guess that you are populating NativeSelect like this:

  nativeSelect.addItem(Locale.ENGLISH);
  nativeSelect.addItem(Locale.GERMAN);
  ...
  // you can also use setItemCaption(objectId, caption) method to give humanized
  // caption to each item in NativeSelect.

之后,您可以在 NativeSelect 组件中添加一个 Property.ValueChangeListener:

After that, you can add a Property.ValueChangeListener to the NativeSelect component:

  nativeSelect.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            Locale loc = (Locale) event.getProperty().getValue();
            UI.getCurrent().setLocale(loc);
        }

  });

这篇关于Vaadin 语言环境的本机选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 21:09