Vaadin的原生地点选择

时间:2013-01-30 16:25:51

标签: java vaadin

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

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

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

1 个答案:

答案 0 :(得分: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.

之后,您可以向Property.ValueChangeListener组件添加NativeSelect

  nativeSelect.addListener(new Property.ValueChangeListener() {

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

  });