gpt4 book ai didi

java - ID 必须存在于容器中或作为生成的列

转载 作者:搜寻专家 更新时间:2023-11-01 03:38:42 26 4
gpt4 key购买 nike

我正在开发一个 vaadin 应用程序,但现在我无法解决以下问题。

我有我的对象模型:

public class MyModel {

private long id;
private Date dValidoAl;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public Date getDValidoAl() {
return dValidoAl;
}

public void setDValidoAl(Date dValidoAl) {
this.dValidoAl = dValidoAl;
}

}

现在我尝试以这种方式将此对象绑定(bind)到 BeanItemContainer:

Table table = new Table();
BeanItemContainer<MyModel> container = new BeanItemContainer<MyModel>(MyModel.class);
table.setContainerDataSource(container);

Object[] visibleProperties = new Object[] { "id", "dValidoAl" };
String[] columnsHeader = new String[] { "Id", "Inizio Validità" };
table.setVisibleColumns(visibleProperties);
table.setColumnHeaders(columnsHeader);

但是我得到这个错误:

Ids must exist in the Container or as a generated column, missing id: dValidoAl

我哪里做错了?

最佳答案

如@Skizzo 发布的那样,并在 Book of Vaadin 中定义,BeanItemContainer(BeanContainer 的实现)将作为 PropertyIds 检查 getter 和 setter。

The item properties are determined automatically by inspecting thegetter and setter methods of the class. This requires that the beanclass has public visibility, local classes for example are notallowed. Only beans of the same type can be added to the container.

在这种情况下,将 DValidoAl 应用为容器的 propertyId 即可执行所需的操作。

关于java - ID 必须存在于容器中或作为生成的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20970196/

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