Waiting dialog close and get the result

How can I get the Dialog result (Yes/No/Cancel) after closing the dialog.

        dialogs.createOptionDialog()
                .withCaption(title + "(" + msgSetNbr + "," + msgNbr + ")")
                .withMessage(defaultMessage)
                .withContentMode(ContentMode.HTML)
                .withType(Dialogs.MessageType.CONFIRMATION)
                .withActions(
                        new DialogAction(DialogAction.Type.YES)
                                .withHandler(e ->  result = Result_Yes),
                        new DialogAction(DialogAction.Type.NO)
                                .withHandler(e -> result = Result_No)
                )
                .show();
        return result;

The code above can not work to get the result. Is there any other approach?
Thanks,

Hi,

The reason why you get no result is that the OptionDialog works asynchronously, as a result, you can’t return something from a dialog. I would recommend invoking required code within DialogAction handlers, e.g.:

dialogs.createOptionDialog()
        .withCaption("Title")
        .withMessage("Message")
        .withType(Dialogs.MessageType.CONFIRMATION)
        .withActions(new DialogAction(DialogAction.Type.YES)
                        .withHandler(e -> {
                            // do something on YES
                        }),
                new DialogAction(DialogAction.Type.NO)
                        .withHandler(e -> {
                            // do something on NO
                        }))
        .show();

Regards,
Gleb

1 Like