Vaadin的原生地点选择

aku*_*zma 1 java vaadin

我正在使用Vaadin.我想使用Native Select在区域设置之间切换.

@Override
public void valueChange(ValueChangeEvent event) {
    UI.getCurrent().setLocale(loc);
}
Run Code Online (Sandbox Code Playgroud)

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

ogz*_*gzd 7

我猜你这样填充NativeSelect:

  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.
Run Code Online (Sandbox Code Playgroud)

之后,您可以添加Property.ValueChangeListenerNativeSelect组件:

  nativeSelect.addListener(new Property.ValueChangeListener() {

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

  });
Run Code Online (Sandbox Code Playgroud)