我正在尝试将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;
} 请帮帮我!
发布于 2015-01-27 15:58:41
您可以使用setValue来设置表中所示的值。并确保在填充它们之前设置了相应的容器属性。
如果您只想知道如何使用SQLContainer将地址簿演示绑定到MySQL数据库,那么可以看看https://vaadin.com/tutorial/sql,它基本上延续了内存容器留给您的内容。
当然,如果你有一些其他的绑定到你的数据JPA,in-memory beans等,你可能想要看看适合你的需要的绑定。
https://stackoverflow.com/questions/28161542
复制相似问题