The strange behavior is when i click outside of the dialog or press Esc the close action is triggered(prints closed), but the dialog does not close. And if i press my cancel button - the dialog is closed, but the close event is not triggered.
That’s by design. According to the javadoc for the Dialog#addDialogCloseActionListener, it says:
Add a listener that controls whether the dialog should be closed or not.
The listener is informed when the user wants to close the dialog by
clicking outside the dialog, or by pressing escape. Then you can decide
whether to close or to keep opened the dialog. It means that dialog won’t
be closed automatically unless you call {@link#close()} method
explicitly in the listener implementation.
NOTE: adding this listener changes behavior of the dialog. Dialog is
closed automatically in case there are no any close listeners. And the
{@link#close()} method should be called explicitly to close the dialog
in case there are close listeners.
That way, it’s up to the server to decide whether or not the dialog will be closed. Meanwhile the action triggered by the button (dialog.close()) won’t dispatch the same event, so that’s why nothing is printed on the console.
That’s by design. According to the javadoc for the Dialog#addDialogCloseActionListener, it says:
Add a listener that controls whether the dialog should be closed or not.
The listener is informed when the user wants to close the dialog by
clicking outside the dialog, or by pressing escape. Then you can decide
whether to close or to keep opened the dialog. It means that dialog won’t
be closed automatically unless you call {@link#close()} method
explicitly in the listener implementation.
NOTE: adding this listener changes behavior of the dialog. Dialog is
closed automatically in case there are no any close listeners. And the
{@link#close()} method should be called explicitly to close the dialog
in case there are close listeners.
That way, it’s up to the server to decide whether or not the dialog will be closed. Meanwhile the action triggered by the button (dialog.close()) won’t dispatch the same event, so that’s why nothing is printed on the console.
what is the event dispatch by button(dialog.close()) ?
That’s by design. According to the javadoc for the Dialog#addDialogCloseActionListener, it says:
Add a listener that controls whether the dialog should be closed or not.
The listener is informed when the user wants to close the dialog by
clicking outside the dialog, or by pressing escape. Then you can decide
whether to close or to keep opened the dialog. It means that dialog won’t
be closed automatically unless you call {@link#close()} method
explicitly in the listener implementation.
NOTE: adding this listener changes behavior of the dialog. Dialog is
closed automatically in case there are no any close listeners. And the
{@link#close()} method should be called explicitly to close the dialog
in case there are close listeners.
That way, it’s up to the server to decide whether or not the dialog will be closed. Meanwhile the action triggered by the button (dialog.close()) won’t dispatch the same event, so that’s why nothing is printed on the console.
what is the event dispatch by button(dialog.close()) ?
There’s no event like that at the moment, although there probably should be. You can work around the issue by extending Dialog; there’s some discussion and a description of a workaround here: https://github.com/vaadin/vaadin-dialog-flow/issues/95
This will make any esc or outside-click call the dialogs close() method. Now we can override that close method and add the code that should always be run at closure:
@Override
public void close(){
System.out.println("closed"); // this will always be printed now, no matter *how* you close the dialog.
super.close();
}