【发布时间】:2016-12-30 08:15:15
【问题描述】:
我无法理解 commit() 方法在 Vaadin 中的实际作用。我阅读了文档,做了一些示例,但我误解了它的实际含义。
这是sn-p的代码:
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);
}
如果我是这样做的,那么我不会添加一些添加到DataSource的Form中的数据(在Container中)。这些条目未显示在表格中。
另一个sn-p代码:
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);
}
这个版本可以正常工作。我可以得出结论,表单中的此方法会阻止与此表单的“数据源”(与数据源中的项目)的所有交互。但我需要直接通过调用另一个类和容器的addItem() 来完成。我还没有找到关于commit() 方法的任何好的解释。
我一直在使用这个tutorial,也许有人会从教程中认出这个GUI。
【问题讨论】:
-
在哪个类中实现了 commit() 方法?应该有文档。 Vaadin 有很好的记录。
-
commit() 做的事情比文档说的要多。请阅读我的问题
-
你还在使用 vaadin 6 吗?
-
是的,这个关于 vaadin6 的教程,但是我通过这个只是为了熟悉创建 gui 表单,因为最新的教程对我来说非常小(而且我没有很好地熟悉)。
-
你读过这个vaadin.com/docs/-/part/framework/datamodel/…吗? (连同数据模型解释?)
标签: java vaadin commit vaadin6