In line browser saving

How can I save a column (id=“a” editable=“true”) in database, in browser screen, programmatically, after I set it?
In Cuba 6 was:

datasourceDs.addPropertyChangeListener(e->datasourceDs.commit());

Best Regards,
-n

Hi,
Could you elaborate on this please? Do you want to save an entity after updating its property?

Yes. Meantime I found this solution, it works but I don;t know if is the right choice:

 datasourceDc.addItemPropertyChangeListener(e -> {
            Entity en = e.getItem();
            dataManager.commit(en);
        });

Regards,
-n

Hi,

I guess a bit more “CUBA”-ish solution might look like this:

    @Inject
    private DataContext dataContext;

    @Subscribe(id = "datasourceDc", target = Target.DATA_CONTAINER)
    public void onDatasourceDcItemPropertyChange(InstanceContainer.ItemPropertyChangeEvent<Entity> event) {
        dataContext.commit();
    }

dataContext is responsible for saving all the changes to the data store, you can read a bit more in the docs about it. And subscribing to events makes your code a bit more clear. There is a great tutorial about it on our site.

Hi Andrey,

Unfortunately (even is more “profi”) your solution doesn’t work.
Don’t ask me why because I don’t know.
My solution still works.
On the other hand maybe you can help me here

because the things are somehow mixed in my mind…set()…dataContext.commit()…dataManager. commit(entity…commitcontext)…detached entities…merge…managed entities…
Every time I have to do multiple tries…it’s hard to find the logic.

Regards,
-n

OK, maybe I should have asked for more info before submitting the example. Good to know that your solution works. Maybe you’ll have time later and provide a small example which we’ll be able to refactor.

It’ pretty easy. When I change (create or update) the value of the date attribute (in the browser screen) I want to save-it (automatically) in the database.
image