Singelton Dialog

I want to write a singleton modal dialog. Due to this link https://vaadin.com/docs/latest/components/dialog/#multiple-dialogs-and-server-side-modality-in-flow this should work per default. But if i close one of the dialogs the other still is open. Is this a bug?

No, if you close only one Dialog only one Dialog gets closed. Why should the other close?

Did you read the documentation link i postet? “Due to the server-side modality mechanism in Flow, this means that closing a modal Dialog automatically also closes all its children, that is, any subsequent Dialogs opened after the modal.”

“This can be avoided by explicitly adding each Dialog to the UI before opening it.” - you haven’t told us how you have added them.

What is a singleton model dialog?

I didnt add the dialog to any ui component. I instantiate the dialog and open it. With singleton i mean only one instance per UI.

What i want is that the dialog didnt open twice. Or if i understand the documentation right - if the modal dialog is closed all instances of the modal dialog will be closed.

If I’m reading you right, you want something like a Notification which doesn’t open more notifications while it’s visible

It is more like a user config dialog which opens if my custom component didn’t have the config so far.

But my question was if the documentation is correct?! Because i read that a modal dialog close all other instances if the dialog was not added to the UI … but i see a different behavior in my application.

I think it could be phrased better. When you open a Dialog, it gets added to the <body> , ie. the UI.

From the JavaDoc: Opens the dialog. Note: You don't need to add the dialog component anywhere before opening it. Since <vaadin-dialog>'s location in the DOM doesn't really matter, opening a dialog will automatically add it to the <body> if necessary.

OK. But why this hint in the vaadin documentation:

Due to the server-side modality mechanism in Flow, this means that closing a modal Dialog automatically also closes all its children, that is, any subsequent Dialogs opened after the modal.

This can be avoided by explicitly adding each Dialog to the UI before opening itDue to the server-side modality mechanism in Flow, this means that closing a modal Dialog automatically also closes all its children, that is, any subsequent Dialogs opened after the modal.

This can be avoided by explicitly adding each Dialog to the UI before opening it

If it doesn’t work like that, then it’s either a bug or the documentation is wrong. I’d recommend creating a GitHub issue about it in Issues · vaadin/flow-components · GitHub with a reproducible example.

As an aside, I haven’t seen your code, but based on your description the behavior sounds like something that can and possibly should be solved in your application’s UI logic. But it’s still worth reporting the disparity between the docs and the component behavior.

What would help could be this convenience API to close all Dialogs added to the UI feat: Add convenience method to close all dialogs of the current UI by TatuLund · Pull Request #4462 · vaadin/flow-components · GitHub

While this API does not exists, you need to maintain list of Dialogs somewhere, e.g. use UI scoped bean to hold the list. So then you can pick that list from there and close all of them before opening a new one.

The documentation says: if you open a dialog (1) then open a new dialog (2) then if you close (1) the dialog (2) will be closed at the same time.

If both dialogs are modal it’s not possible on the client side. But if the dialogs are not modal then it’s possible and it can be an unwanted behavior ( it’s a breaking change)

If you don’t want to create 2 instances of the dialog then you can check if there is an existing instance before creating a new instance. But nothing is done in Vaadin to prevent that.