Remove Button on Edit Screen

Hi,

I’m using Cuba Platform v7 and I’m trying to add a Remove Button (to remove currently edit entity) directly from the Edit Screen.
There is no problem to create the button, but I don’t know how to do the operation by code.

In the previous version there was removeItem() method, but now?

Thank You

Hi,

You can use the DataManager bean, e.g.:

@Inject
private DataManager dataManager;

@Subscribe("removeBtn")
private void onRemoveBtnClick(Button.ClickEvent event) {
    if (!PersistenceHelper.isNew(getEditedEntity())) {
        dataManager.remove(getEditedEntity());
        // It's better to provide own action Id 
        // in order to handle remove in a browser screen 
        close(new StandardCloseAction("remove"));
    }
}

Regards,
Gleb

1 Like

Hi Gleb,

I tried your solution and the entity is deleted but the browse table did not reload automatically. Can you help?

Thank you.