1

I have some problem with understanding what the commit() method really does in Vaadin. I read the documentation, did some examples but I am misunderstanding what it actually is.

This is snippet of code:

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 I do things this way, then I don't add some of the data added in the Form of the DataSource (in the Container). Those entries aren't showing in the table.

Another snippet of code:

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);
}

This version works correctly. I can conclude that this method in the form do block for all interactions with "DataSource" (with items in DataSource) for this Form. But I need to do it directly, through invocation another class and Container's addItem(). I haven't found any good explanation about commit() method.

I have been using this tutorial, maybe someone will recognize this GUI from the tutorial.

GUI

Alex
  • 3,923
  • 3
  • 25
  • 43
  • in which class is the commit() method implemented? There should be a documentation. Vaadin is well documented in generel. – d2k2 Aug 23 '16 at 14:18
  • commit() do more things than documentation said. Read my question please – Alex Aug 23 '16 at 14:25
  • are you still on vaadin 6? – André Schild Aug 23 '16 at 14:31
  • Yes, this tutorial about vaadin6 but i have been passing through this only for familiarization with creating gui forms because the newest tutorial is very small for me( and i didn't get a good familiarization). – Alex Aug 23 '16 at 14:35
  • Have you read this https://vaadin.com/docs/-/part/framework/datamodel/datamodel-itembinding.html? (Along with the data model explanations?) – André Schild Aug 23 '16 at 14:46
  • Yes, thanks, i did. If you can, please explain me what is wrong in first snippet of code. – Alex Aug 23 '16 at 14:51

1 Answers1

0

I understood what is wrong. In the second snippet i filled out my newPerson instance with data from form by invocation of commit(). In the first snippet i have written null data because i didn't invoke method commit() before and binding object is null(not written yet).

Alex
  • 3,923
  • 3
  • 25
  • 43