Vaadin - 如何从 bean 项目容器中的 bean 项目的对象 ID 获取 bean 本身

Vaadin - How to get a bean itself from the object id of the bean item in a bean item container

我已经为 ComboBox this.comboBox.setContainerDataSource(container) 设置了一个 ContainerDataSource。这个容器是一个 BeanItemContainer。 此外,我创建了 TextFields,它绑定到来自 BeanItemContainer 的 bean 的某些属性。要获取 ComboBox 的选定数据,我只能执行 this.comboBox.getValue(),其中 returns 选定 bean 的对象 ID。我如何使用此信息来获取实际选择的 bean 本身?我需要它来设置字段组中我的文本字段的项目数据源。

final BeanItemContainer<Person> personContainer = new BeanItemContainer<>(Person.class);
for(int h = 0; h <= this.table.getSelectedItems().size() -1; h++) {
final Person person = this.table.getSelectedItems().get(h).getBean();    
personContainer.addBean(person);}
final Window win = new Window("Person", new PersonView(personContainer));
this.getUI().addWindow(win);

人物视图:

public PersonView(final BeanItemContainer<Person> personContainer) {
    super();
    this.initUI();

    this.comboBox.setContainerDataSource(personContainer);
    this.comboBox.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    this.comboBox.setItemCaptionPropertyId("name");

    }
private void comboBox_valueChange(final Property.ValueChangeEvent event) {
    //this.fieldGroup.setItemDataSource(...);
}

我假设您使用的是 Vaadin 7。

这是从 ComboBox 中获取所选项目的解决方案。:

        comboBox.addValueChangeListener( new ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {

                Person person = (Person) comboBox.getValue();

                //do something with the selected value
                this.fieldGroup.setItemDataSource(person);              
            }
        });