Method "refresh" in a screen controller

I noticed that every time you move from one screen to another already open, the latter is refreshed (we see appear for a short time a loading indicator).
In this case, the controller "ready () " method is not called, while is called each time you re-create the screen (I tried inserting simple log.debug in controller code).

Is there a method that is invoked everytime a screen is refreshed that can be used in a controller?

I would need it, because I’ve created a javascript function (using jquery) that set at will the layout of some html template used in a HtmlBoxLayout (; these functions are properly carried out in the ready () method of the controller… unfortunately when I switch to another tab and the then go back, the screen is refreshed, but without running the javascript function.
Instead everything is ok if you close and reopen the screen… the ready() method is invoked and so the javascript function.

Thank you,



Our screens does not have refresh event, so you cannot handle screen visibility change on a servers side. Instead of a server side event you can use JavaScript extensions functionality from Vaadin to handle client side visibility change.

Vaadin extensions are described here:

In a case of CUBA application, you can use this mechanism in web modules. Let assume you want to create simple listener that will show browser alert if HtmlBoxLayout is shown in browser.

First, create Java class DemoExtension that will extend AbstractJavaScriptExtension class from Vaadin:

public class DemoExtension extends AbstractJavaScriptExtension {
    public DemoExtension(CustomLayout target) {

Here we connect server side class DemoExtension to client side JavaScript file.

Next, create JavaScript file in modules/web/web/VAADIN/ with name demo-extension.js:

// register extension
window.com_company_demo_web_DemoExtension = function() {
    var self = this;
    var element = self.getElement(self.getParentId());

    window.alert('Element ' + element + 'is shown!');

There define the function with a special name; it should be equal to FQN of server side Java class. This function will be called when our Component becomes visible on client side.

And finally, create an extension instance in a screen using Vaadin component, obtained from CUBA component (see unwrap method):

public class Screen extends AbstractWindow {
    private HtmlBoxLayout htmlBox;

    public void init(Map<String, Object> params) {

        CustomLayout layout = htmlBox.unwrap(CustomLayout.class);
        new DemoExtension(layout);

Now, when you switch back to the screen with HtmlBoxLayout connected to the extension a standard browser alert will be shown.

The extension completely depends on its component, so it will be invoked on client side only when its component is visible to client side. In our case this component is HtmlBoxLayout.

I’ve prepared simple demo for you, see project on github

Hi Yuriy,
thank you very much for your explanation.
My error was to use the method


that the controller call only once per screen creation.
Using your code, did the trick: everytime I switch back to the screen, the javascript is invoked.
have a nice day,