问题
I'm using Vaadin. I want to use Native Select to switch between locales.
@Override
public void valueChange(ValueChangeEvent event) {
UI.getCurrent().setLocale(loc);
}
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?
回答1:
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.
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);
}
});
来源:https://stackoverflow.com/questions/14608819/native-select-of-locale-in-vaadin