modal dialog openWindow not waiting for answer before continuing execution?

I have the following code:

    private void check_bad_debt(Mailfile selected) {
        badDebtDs.refresh(ParamsMap.of("lname", selected.getLname(), "postalCode", selected.getZip()));
        if (badDebtDs.getItemIds().size() > 0) {
                            ParamsMap.of("lname", selected.getLname(), "postalCode", selected.getZip())
            ).addCloseListener(actionId -> {
                    if (actionId.equals("onReject")) {
                        badDebt = true;
                    if (actionId.equals("onAccept")) {
                        badDebt = false;

with this screen declaration:

<window xmlns=""
        caption="Possible Bad Debt "
    <dialogMode closeable="true"

When I call this routine, I expected it to pop up the modal dialog under the correct conditions and wait for the user to click a button. Instead, the check_bad_debt function returns immediately, THEN the window opens up and the CloseListener fires when a button is pressed.

What I am trying to accomplish is that the data source is checked for data given a set of parameters. If there is data given those parameters, the modal window comes up and the user then gets the option to accept or reject the data. If they accept the data, then the process continues. If they reject the data, then the form is reset. How best to accomplish this?


Any dialog is just UI component that is shown on a web page. Because of web nature of our components we cannot block code execution until a dialog return value. So, if you want to react on user action/dialog close/commit/etc you have to add CloseListener or CloseWithCommitListener to dialog as a callback. And a dialog opening will return immediately.

In your case you can break execution process using return or, and when user clicks on button repeat your action. Another option is to force all the code base to use callback model or something like Promise/CompletableFuture.

Sometimes you cannot break current execution, for instance it is hard/impossible to show such a dialog during DB transaction.

OK, thanks. I was afraid of that. I will try to restructure my code.