ConfirmDialog plugin and returning a boolean value

Greetings, I have tried to use the plugin “ConfirmDialog” to return a boolean depending on what the user needs, this is what I have so far:

public static boolean showQuestion(String message)
{
    final boolean[] confirmed = {false};

    ConfirmDialog.show(
        UI.getCurrent(),
        "¿Are your sure?:",
        message,
        "Yes",
        "No",
        new ConfirmDialog.Listener() {
            public void onClose(ConfirmDialog dialog) {
                if (dialog.isConfirmed()) {
                    // Confirmed to continue
                    confirmed[0]
=true;
                } else {
                    // User did not confirm
                    confirmed[0]
=false;
                }
            }
        }
    );

    return confirmed[0]
;
}

My problem is that it always returns the false value.

What am I doing wrong?.

Thanks in advance for the help.

ConfirmDialog.show() does not block until a response has been received, so your method will always return the initial value of confirmed[0] , which is false. The programming model does not allow blocking for a response, you will need to add a listener in the caller instead and continue when the listener is triggered.