How to disable unsaved changes screen

Hi, Id like to avoid seeing this screen on an standard editor.

image

In one screen I already have it as read only the other one I just dont want it to appear. How can I avoid seeing this screen?

I cant put closeWithDiscard() on the the little X button since its the cuba tab close button.

Thank you for the constant help!

Hi,

There are several ways to achieve this:

  1. Override the hasUnsavedChanges method in the editor screen:
@Override
public boolean hasUnsavedChanges() {
    return false;
}
  1. Override the preventUnsavedChanges method in the editor screen:
@Override
protected void preventUnsavedChanges(BeforeCloseEvent event) {
    // do nothing
}
  1. Use custom Close Action in the editor screen that will not check for unsaved changes:
public class ProductEdit extends StandardEditor<Product> {

    private final CloseAction CUSTOM_WINDOW_CLOSE_ACTION
            = new StandardCloseAction(Window.CLOSE_ACTION_ID, false);

    @Override
    protected void cancel(Action.ActionPerformedEvent event) {
        close(commitActionPerformed ?
                WINDOW_COMMIT_AND_CLOSE_ACTION : CUSTOM_WINDOW_CLOSE_ACTION);
    }
}

Regards,
Gleb

4 Likes

Thank you so much !!!