AbstractWindow.ready() method does not behave as expected

As the title says, the AbstractFrame.ready() method does not behave the way it’s documentation says.

Called by the framework after the screen is fully initialized and opened.

Override this method and put custom initialization logic here.

Let’s consider the following scenario:

  1. Window1 opens Window2 with: openWindow("Window2", .THIS_TAB, someParams);
  2. Window2 opens in it’s ready() function Window3 with: openWindow("Window3", .NEW_TAB, someOtherParams);
  3. Window3 is a heavier window, so it takes aprox. 10 seconds to open.

Expected behaviour: Window1 opens Window2 in the same tab, then, with Window2 viewable, Window2 opens Window3 in new tab.
Actual behaviour: Window1 stalls untill Window2 AND Window3 are completely rendered then opens Window2 in the current tab and Window3 in a new tab at the same time.

Am I missing something, or this is the intended behaviour? I am using VAADIN engine for front-end rendering. And all the openWindow commands are executed from AbstractWindow sons’ controller.

If needed I will provide more context to my question as to why I need ready() to behave EXACTLY as the docs say.

Thank you,
Alex

It means not the client-side opening, but server-side. In fact, all the data sources of a screen are loaded and UI components added to UI tree. It does not mean that all UI objects sent to client.

Web Client is server-side framework, thus all changes in UI are shown after request processing is finished. You cannot wait until screen is opened, but you can open the next screen by Timer (or after delay).

In case of long operations please consider using BackgroundTask: https://doc.cuba-platform.com/manual-6.8/background_tasks.html

1 Like

Thank you @artamonov for the very fast answer.

Can you show me an example in which you user Timer and open Window3 from my example using a delay of 1 second? The Timer should be in the ready() method of Window2.

Thank you again,

Alex

Define timer in the first window:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://caption"
        class="com.company.timerdelay.web.screens.ScreenFirst"
        messagesPack="com.company.timerdelay.web.screens">
    <timers>
        <timer id="delayedOpenScreen2"
               autostart="true"
               delay="500"
               onTimer="openSecondScreen"/>
    </timers>
    <layout>
        <label stylename="h2"
               value="FIRST"/>
    </layout>
</window>

On timer open the second screen:

public class ScreenFirst extends AbstractWindow {

    public void openSecondScreen(Timer source) {
        openWindow("screen-second", OpenType.NEW_TAB);
    }
}
1 Like