How to add a save confirmation dialog

Can anyone help me to add a save confirmation dialog to an Edit screen? I would like to add a “Yes” / “No” dialog screen to confirm saving when the “OK” button is clicked. If “Yes” selected, then the record is saved. If “No” selected, the control should return to the Edit screen without saving.

Override the commitAndClose() method in your screen controller:


public class CustomerEdit extends AbstractEditor<Customer> {
    @Override
    public void commitAndClose() {
        showOptionDialog(
                "Confirm",
                "Are you sure you want to save changes?",
                MessageType.CONFIRMATION,
                new Action[] {
                        new DialogAction(DialogAction.Type.YES) {
                            @Override
                            public void actionPerform(Component component) {
                                CustomerEdit.super.commitAndClose();
                            }
                        },
                        new DialogAction(DialogAction.Type.NO)
                }
        );
    }
}

Thanks Konstantin.

Before this, I managed to do it in preCommit(). Very interesting to see this using the commitAndClose() also.