Hi,
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:
@JavaScript("vaadin://demo-extension.js")
public class DemoExtension extends AbstractJavaScriptExtension {
public DemoExtension(CustomLayout target) {
super(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 {
@Inject
private HtmlBoxLayout htmlBox;
@Override
public void init(Map<String, Object> params) {
super.init(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 GitHub - cuba-labs/clientside-visibility.