java - Vaadin - 如何从 bean 项目容器中 bean 项目的对象 id 获取 bean 本身
问题描述
我为 ComboBox 设置了一个 ContainerDataSource this.comboBox.setContainerDataSource(container)
。这个容器是一个 BeanItemContainer。此外,我创建TextFields
了绑定到 .bean 的某些属性的BeanItemContainer
. 为了获取ComboBox
I only can do的选定数据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);
人物视图:
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);
}
});
推荐阅读
- jquery - 数据更改时如何在制表器中突出显示单个单元格
- javascript - 修复 on_click 函数以更改文本
- php - Laravel Consolestvs\charts - 在图表中显示属于登录的特定用户的数据
- javascript - 循环遍历包含对象的数组对象
- c# - Gradle 启动失败:意外令牌:...@ 第 83 行,第 7 列
- python - 您如何比较两个随机生成的列表以找到共同的元素
- python - 当子元素使用 selenium 匹配文本时选择父子元素
- javascript - AudioContext:声音不在 Chrome 中播放,但在 Internet Explorer 中工作,但在我注释掉 createMediaElement?t 时工作人员
- c++ - 将成员函数分配给实例成员的属性
- java - 如何在jshell中为spring项目设置类路径