gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:29:11 25 4
gpt4 key购买 nike

我已经为 ComboBox 设置了 ContainerDataSource this.comboBox.setContainerDataSource(container)。这个容器是一个 BeanItemContainer。此外,我还创建了 TextFields,它们绑定(bind)到 BeanItemContainer 中 bean 的某些属性。为了获取 ComboBox 的选定数据,我只能执行 this.comboBox.getValue(),它返回选定 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);

人物 View :

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);
}
});

关于java - Vaadin - 如何从 bean 项目容器中的 bean 项目的对象 id 获取 bean 本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58113859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com