How to detect page reloads on UIs with @PreserveOnRefresh

Hi,

I have build a JavaScriptExtension that extends a CssLayout and applies
Roundabout
to it.

When I add items to the layout I have to call a refresh function so the Extension can invoke the jquery plugin.

It works ok when a new UI gets created on page reload.

But if I use the UI with @PreserveOnRefresh and the UI gets restored after a page reload I have found no way to notify the Extension to refresh the Roundabout layout. Currently I am using View#enter to trigger the refresh function but it doesn’t fire after a reload.

I understand this logic because the view did not actually change, but is there any Event that fires even when the page was preserved?

To detect page refresh on server side, override com.vaadin.server.ClientConnector.beforeClientResponse(boolean) in your server-side component. This will be called before the shared state and RPC calls of the component are sent to the client, and the boolean parameter will be true when the client-side connector does not yet exist; it should be true when the page is refreshed. See the javadoc of that method for some details.

Hi Teppo,

thank you for your reply. Because I use an AbstractJavaScriptExtension I try to avoid to create a real widget. But your answer has pointed me to the right direction.

I have created a new event on my extension. At the end of my JavaScript client part constructor i call a function that triggers the new event on the Java server side. In the listener I call the refresh method. When it reaches the JavaScript part again, the layout is ready and it works after reload, now! :slight_smile:

Hi Max,

glad you got it working :slight_smile: Although I didn’t quite follow what you mean by the creating a real widget. The Extension interface extends the ClientConnector interface so the beforeClientResponse method should be available in your AbstractJavaScriptExtension too. Or did I miss something?

Ahh, I think I misunderstood the logic behind the extension itself. Somehow I was looking for the method in my CustomComponent. Your suggestion works, too.

Thanks for enlighten me!