我正在使用 Vaadin 。我想使用Native Select在区域设置之间切换。
@Override
public void valueChange(ValueChangeEvent event) {
UI.getCurrent().setLocale(loc);
}
我想使用event.getProperty()
,但“loc”必须是Locale类型。如何获得原生选择的值并将其转换为Locale类型?
答案 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);
}
});