Update Table values after user confirmation

Hello,
I tried to find the answer through the forums because it seems a so simple one, but I couldn’t…

I have the following (typical) situation: a Table, linked to my own Container (connected to a db), and a Form that displays the data currently selected. Three buttons “New”, “Remove”, “Apply” which of course add a new Item, remove the selected Item, and (should!) update the current Item based on the Form value. This latter point is where I have some problems: the Form is linked to the Item present in the Table, so the object is effectively changed but the visualization is not.

How can I tell the Table that the object is changed? For the first two buttons I managed to use an elegant way, this is the wrapper for the listener:

public void onNewProjClick() {
        projTable.select(projTable.addItem());
    }
    public void onRemoveProjClick() {
        projTable.removeItem(projTable.getValue());
    }
    public void onApplyProjClick() {
        ???????
    }

But for the “Apply” I tried several things without success… Can someone give me a suggestion, please?
Thanks
M.

From your code, I dont really understand what you’re trying to do. Anyway, this i what I have to suggest…

First on click or table selection, get the Item object, which you use to fill the form. Using this item object, you change Property values which are reflected in the table.

item.getItemProperty(property_name).setValue(new_property_value);

I hope this helps.

Thank you for your reply, however this is what I exactly did… sorry for the code, but I summarized it too much… here is a better picture:


public void onTableClick() {
        Object id = entityTable.getValue();
        if (id==null) entityForm.setItemDataSource(null);
        else entityForm.setItemDataSource(entityTable.getItem(id),entities.getContainerPropertyIds());
    }
    
    public void onNewClick() {
        entityTable.select(entityTable.addItem());
    }
    
    public void onRemoveClick() {
        entityTable.removeItem(entityTable.getValue());
    }
    
    public void onApplyClick() {
        Object itemId=entityTable.getValue();
        entities.updateItem(entityForm.getItemDataSource());
        entityTable.setContainerDataSource(entities); // I DO NOT LIKE THIS METHOD!
        entityTable.setValue(itemId);
    }

// This is contained in the "entities" class:
    public void updateItem(Item item) {
        Item oldItem=this.getItem(item.getItemProperty("id"));
        for(int i=1;i<colsNames.length;i++) {
            oldItem.getItemProperty(colsNames[i]
).setValue(item.getItemProperty(colsNames[i]
).getValue());
        }
    }

“entityTable” is the table, “entityForm” is the form, “entities” is the container. The code you suggested is executed in the updateItem method called after one clicks the “Apply” button, but the corresponding row in the table is not updating…
As you can see, I managed to solve it temporarily by setting again the data source, but I do no feel it is the correct (and efficient) way to do it.
What can be wrong?