Closing a Dialog via esc or outsideClick does not trigger Dialog::close?

I have a Dialog that must trigger a refresh of a Grid when the Dialog is closed.
In that Dialog I have a Runnable onClose defined that is run in the close() method that I have overridden:

public void close(){
    if (onClose != null) {;

I have added a Button that closes the Dialog (new Button("Close", click -> this.close())). Everything works great so far.

But now I want to allow closing the Dialog also via esc or an outside-click (setCloseOnEsc(true), setCloseOnOutsideClick(true)). I thought that my overriding of the close() method was enough here, but it appears that close() is not even called when pressing esc or clicking outside.

Is there some explanation why it is done like that, or a workaround, or is this a bug?

I think you’re looking for Dialog::addDialogCloseActionListener. That, in combination of your override, should cover all the cases of closing a Dialog. The close method is not an event listener, so I would not expect it to be executed when something happens on the client.

There is a related open bug ticket: . Personally, I feel like there could be a Dialog::addCloseListener which would get triggered regardless of where the close event originated from, but then, adding another listener might make the API more confusing.

Thank you Olli for the fast response. It seems listening to DialogCloseActionEvent is indeed the solution.
I am however a little confused about what else is going on inside the method Dialog::addDialogCloseActionListener. I have now extracted only the following line from said method into the Constructor of my Dialog-extension class:

addListener(DialogCloseActionEvent.class, event -> this.close());

This line singlehandedly solves all my issues. It makes sure that my close method is called also for esc and outside clicks. (tested, it works)

IMO this could/should be done by default in the Dialog constructor, but I also realize I might not be seeing the big picture. I for one would welcome the idea of a Dialog::addCloseListener. I think it’s more confusing (to me) that there isn’t such a method and that I had to go through this very process to run some code when the dialog closes no matter how it was closed. But then again there are more things involved than meets the eye, and I don’t take these into consideration when writing this. Therefore I wont be making a github issue for this, I trust you guys to do what’s best here :wink: