2014-01-07 16 views
4

我正在開發一個vaadin應用程序,現在我無法解決以下問題。ID必須存在於容器中或作爲生成的列

我有我的對象模型:

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

} 

現在,我想這個對象的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

我在哪裏做錯了?

+2

'tableContainer.getContainerPropertyIds()'返回什麼?那裏有'dValidoAl'嗎? –

+1

我在tableContainer.getContainerPropertyIds()中發現了DValidoAl而不是dValidoAl,並且我用「DValidoAl」更改了屬性「dValidoAl」的名稱,現在一切正常。謝謝 – Skizzo

+0

@Skizzo請將您的解答作爲答覆並接受它!謝謝! – Krayo

回答

1

由於@Skizzo發佈,並且在Book of Vaadin中定義,BeanItemContainer(BeanContainer的實現)將作爲PropertyIds檢查獲取者和設置者。

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

在這種情況下,應用DValidoAl你可以做你需要的操作容器的屬性ID。

相關問題