Native Select of Locale in Vaadin

谁说我不能喝 提交于 2020-01-03 03:01:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!