How to update data in datasource only on save button click?

I have several text fields describing some configuration. When I launch my app these fields are filled with data from file. I also have 3 buttons - edit, save and cancel. Edit activates save and cancel buttons, and also discards read only from text fields. If I change data in text fields and click cancel the data still saves and file is changed.

Here is my bean:

public class Config implements Serializable {
    private String address = "";
    private String uri = "";
    private String host = "";

    public String getAddress() {
        return ConfigUtil.getInstance().getAddress();

    public void setAddress(String address) throws ConfigException {

And container:

public class ConfigContainer extends BeanItem<Config> implements Serializable {

    public ConfigContainer(Config bean) {

And this is my UI:

public class ConfigSettings extends Panel {
    private TextField addressField = new TextField("Address: ");
    private TextField uriField = new TextField("URI: ");
    private TextField hostField = new TextField("Host: ");
    public ConfigSettings() {
         //add components

         //read data

I don’t have setImmediate on any of components. And I even don’t have any save/cancel logic on buttons, but data is still saved :frowning:
What is wrong here and how to correct it?


saleButton.addClickListener( new Button.ClickListener() {


} ) ;

Something along that line.

However , To ensure that data is never parially commited ( ie due to validation etc. ) you should decouple the Bean from the source.
The bean should be a simple POJO,
Read its values from the ConfigUtil.getInstance()
make a Form with your bean as Item.
only when form.commit() succeeds do you write the values of your bean to ConfigUtil.getInstance() …

Thanks, it helped me a lot. And as a result I reworked this class to generate form via FieldGroup. Now it saves only when commit is called :slight_smile: