Save entity when editing in editable table

In my point of view, if i have the ability to make entities editable in a table, the edited content should be saved too. Can you add a short sample which handler should implement what, to save content edited in the table ?
Thank you

Here it is:

Descriptor:

<window>
    <data readOnly="false">
    <layout>
        ...
        <groupTable id="departmentsTable"
                    dataContainer="departmentsDc" editable="true">
            <columns>
                <column id="name" editable="true"/>
            </columns>
            <buttonsPanel id="buttonsPanel">
                ...
                <button id="saveBtn" caption="Save"/>
            </buttonsPanel>

Controller:

@UiController("Department.browse")
@UiDescriptor("department-browse.xml")
@LookupComponent("departmentsTable")
public class DepartmentBrowse extends StandardLookup<Department> {

    @Autowired
    private DataContext dataContext;

    @Subscribe("saveBtn")
    public void onSaveBtnClick(Button.ClickEvent event) {
        dataContext.commit();
    }
}

So you should make sure attribute readOnly is absent or false for the data element (it affects the screen’s DataContext), set editable="true" for the table and columns, and add a button which invokes dataContext.commit() to save the changes.

Dear Konstantin

Thank you for your help

I found what i was searching by using


public void onDepartmentDcItemChange(InstanceContainer.ItemChangeEvent<TNL> event) {
    dataContext.commit();
}

As soon as the user leaves an editable field it will be saved. In my opinion, this should be standard in the generated code ?

Now it would be great to have a Ctrl-Z function, means undo the last commit’s. Is there already a solution for this available ?

Best regards

Felix

Hi Felix,

Is it a question or a recommendation?

Do you mean the whole record in the database?
No, it would require some kind of versioning implemented on the model and business logic level.

Hi Konstantin
→ this I see as a recommandention. If a field is editable, it should be stored too. In the edit window, the changes in the fields are stored too to the database.
→ about undo. I could imagine, as there is already a log of the changes ( including soft delete ) this could be a nice feature to have.
I will now apply to all my browsewindows the store procedure or perhaps derive the StandardLookup.