如何使用特定值而不是伪随机填充表?

时间:2015-01-27 00:59:26

标签: eclipse vaadin addressbook

我试图将vaadin地址簿应用程序修改为稍微不同的应用程序,只更改了字段名称。但我不知道如何使用特定值而不是像vaadin教程示例中所做的伪随机填充它。 这是我的代码。

private static IndexedContainer createDummyDatasource() {    
    IndexedContainer ic = new IndexedContainer();    
    for (String p : fieldNames) {    
    ic.addContainerProperty(p, String.class, "");    
    }    
    String[] cnumber = { "1", "2", "3" };    
            String[] ctitle = { "a", "b", "c" };    
            String[] faculty = { "xxx" };    
            for (int i = 0; i < 3; i++) {    
            Object id = ic.addItem();    
            ic.getContainerProperty(id, CNUMBER).setValue(cnumber[(int) (cnumber.length * Math.random())]);    
            ic.getContainerProperty(id, CTITLE).setValue(ctitle[(int) (ctitle.length * Math.random())]);    
            ic.getContainerProperty(id, FACULTY).setValue(faculty[(int) (faculty.length * Math.random())]);    
            }    
            return ic;    
            }    

请帮助.. !!

1 个答案:

答案 0 :(得分:1)

使用setValue设置表中显示的值。并且还要确保在填充它们之前设置相应的容器属性。

如果您只是想知道如何使用SQLContainer将地址簿演示绑定到MySQL数据库,那么您可以查看https://vaadin.com/tutorial/sql几乎继续内存容器离开的位置你。

当然,如果您对数据JPAin-memory beans等有其他约束力,那么您可能需要根据自己的需要查看相应的数据。

相关问题