Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Vaadin Form commit()方法?_Java_Vaadin_Commit_Vaadin6 - Fatal编程技术网

Java Vaadin Form commit()方法?

Java Vaadin Form commit()方法?,java,vaadin,commit,vaadin6,Java,Vaadin,Commit,Vaadin6,我在理解commit()方法在Vaadin中的实际作用时遇到了一些问题。我阅读了文档,做了一些示例,但我误解了它的实际内容 这是一段代码: if (source == save) { /* If the given input is not valid there is no point in continuing */ if (!isValid()) { return; } if (newContactMode) { /*

我在理解
commit()
方法在Vaadin中的实际作用时遇到了一些问题。我阅读了文档,做了一些示例,但我误解了它的实际内容

这是一段代码:

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);
}
如果我这样做,那么我就不会添加一些以数据源的形式添加的数据(在容器中)。这些条目没有显示在表中

另一段代码:

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);
}
这个版本工作正常。我可以得出这样的结论:表单中的这个方法会阻止与该表单的“数据源”(数据源中的项)的所有交互。但我需要通过调用另一个类和容器的
addItem()
,直接执行此操作。关于
commit()
方法,我没有找到任何好的解释

我一直在使用这个,也许有人会从教程中认出这个GUI


我明白什么是错的。在第二个代码段中,我通过调用commit()用表单中的数据填写了我的newPerson实例。在第一个代码段中,我编写了null数据,因为我以前没有调用commit()方法,并且绑定对象为null(尚未编写)。

我理解了问题所在。在第二个代码段中,我通过调用commit()用表单中的数据填写了我的newPerson实例。在第一个代码段中,我编写了null数据,因为我以前没有调用commit()方法,绑定对象为null(尚未编写)。

commit()方法是在哪个类中实现的?应该有一份文件。Vaadin在generel中有很好的文档记录。commit()做的事情比文档中说的要多。请阅读我的问题您是否仍在使用vaadin 6?是的,本教程是关于vaadin 6的,但我通过本教程只是为了熟悉创建gui表单,因为最新的教程对我来说非常小(我没有很好地熟悉)。您阅读了本教程吗?(与数据模型解释一起?)commit()方法是在哪个类中实现的?应该有一份文件。Vaadin在generel中有很好的文档记录。commit()做的事情比文档中说的要多。请阅读我的问题您是否仍在使用vaadin 6?是的,本教程是关于vaadin 6的,但我通过本教程只是为了熟悉创建gui表单,因为最新的教程对我来说非常小(我没有很好地熟悉)。您阅读了本教程吗?(连同数据模型说明?)