我正在使用Vaadin.我想使用Native Select在区域设置之间切换.
@Override
public void valueChange(ValueChangeEvent event) {
UI.getCurrent().setLocale(loc);
}
Run Code Online (Sandbox Code Playgroud)
我想使用,event.getProperty()但"loc"必须是Locale类型.如何获得原生选择的值并将其转换为Locale类型?
我猜你这样填充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.ValueChangeListener到NativeSelect组件:
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)