Table and setWriteThrough(false)

Seems that I have misunderstood how write-through works.

I have made this small test case for Vaadin 6.4.2.

package test;

import com.vaadin.Application;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.Table;
import com.vaadin.ui.Window;

public class TestApplication extends Application {
  private static final long serialVersionUID = 1L;
  
  public class TestBean {
    private String testValue;

    public String getTestValue() {
      return testValue;
    }

    public void setTestValue(String testValue) {
      this.testValue = testValue;
    }
  };
  
  public class TestBeanDS extends BeanItemContainer<TestBean> {
    private static final long serialVersionUID = 1L;
    public TestBeanDS() {
      super(TestBean.class);
    }
    @Override
    public BeanItem<TestBean> addItem(Object itemId)
        throws UnsupportedOperationException {
      System.out.println("Item added to datasource!");
      return super.addItem(itemId);
    }
  };
  
  @Override
  public void init() {
    Window mainWindow = new Window();
    setMainWindow(mainWindow);
    mainWindow.setSizeFull();
    
    Table testTable = new Table();
    testTable.setContainerDataSource(new TestBeanDS());
    testTable.setWriteThrough(false);
    testTable.setEditable(true);
    
    mainWindow.addComponent(testTable);
    
    System.out.println("Adding first item to table!");
    testTable.addItem(new TestBean());
    
    System.out.println("Adding second item to table!");
    testTable.addItem(new TestBean());
  }
}

The output to System.out is:

Adding first item to table!
Item added to datasource!
Adding second item to table!
Item added to datasource!

Shouldn’t the items first be added to the data source when a commit() is called on the table?
And why not?

Hi,

Write-trough only applies to the
value
(selection) of the Table, not the content (items).

Interesting question, though - I can see how that could be unclear.

Best Regards,
Marc

Thank you.

You can implement commit and rollback support to table with Lazy Query Container add-on.

-Tommi