Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Editable Table value change SQLContainer commit
Can anyone help me with this? This is propably incredibly easy and I'm just doing it very wrong.
I'm trying to do the following:
- I have a table with an SQLContainer data source
- The cells are made editable with ColumnGenerator
- As soon as a value in the table is changed I want it to cause the SQLContainer to call commit
Table table = new Table();
// ...
table.setContainerDataSource(container);
// ...
table.addGeneratedColumn("COLUMN", new MyColumnGenerator());
And from MyColumnGenerator.java
@SuppressWarnings("unchecked")
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
Component c;
Item item = source.getItem(itemId);
Property<String> prop = item.getItemProperty(columnId);
if (SessionUtils.isAuthentified()) {
TextField tf = new TextField();
tf.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
try {
((SQLContainer)source.getContainerDataSource()).commit();
} catch (Exception e) {
Notification.show(
"Unable to update data.",
Notification.Type.ERROR_MESSAGE);
}
}
});
tf.setPropertyDataSource(prop);
c = tf;
} else {
Label lb = new Label();
lb.setPropertyDataSource(prop);
c = lb;
}
return c;
}
But the above example causes some kind of infinite error-loop (most often I do not even get exceptions). How to do this properly? Can I somehow cause the SQLContainer to commit automatically when changes occur?
Thanks in advance for your time to read this post.
(EDIT: Ok I figured this out and simply used container.setAutoCommit(true) instead of all the other shenanigans, which works just fine. However, out of curiosity, how would you do this if you did not want to use auto-commit?)