1
我在理解Vaadin中的commit()
方法真的有些问题。我阅读了文档,做了一些例子,但我仍然误解它的实际内容。Vaadin Form的commit()方法?
这是代码片段:
if (source == save) {
/* If the given input is not valid there is no point in continuing */
if (!isValid()) {
return;
}
if (newContactMode) {
/* We need to add the new person to the container */
Item addedItem = app.getDataSource().addItem(newPerson);
/*
* We must update the form to use the Item from our datasource
* as we are now in edit mode
*/
setItemDataSource(addedItem);
//System.out.println(app.getDataSource().getItem(addedItem));
newContactMode = false;
}
commit();
setReadOnly(true);
}
如果我这样做事,那么我不添加一些我在表单中的数据源写的数据(在容器)的。这些条目未在表格中显示。
另一个代码片段:
if (source == save) {
/* If the given input is not valid there is no point in continuing */
if (!isValid()) {
return;
}
commit();//changing place of this method
if (newContactMode) {
/* We need to add the new person to the container */
Item addedItem = app.getDataSource().addItem(newPerson);
/*
* We must update the form to use the Item from our datasource
* as we are now in edit mode
*/
setItemDataSource(addedItem);
//System.out.println(app.getDataSource().getItem(addedItem));
newContactMode = false;
}
setReadOnly(true);
}
这个版本可以正常工作。我可以得出结论,表单中的这个方法会阻止与此表单的“DataSource”(包含DataSource中的项目)的所有交互。但我需要通过直接调用另一个类和Container addItem()
来手动完成。我还没有找到任何关于commit()
方法的好解释。
我一直在使用这tutorial,也许有人会从教程中认识到这个GUI。
在哪个类中实现了commit()方法?应该有一个文件。 Vaadin在generel中有很好的记录。 – d2k2
commit()比文档说的做更多的事情。请阅读我的问题 – Alex
你还在vaadin 6? –