Reputation: 5266
I have the following scenario. Javascript is executed in the frontend and reacts on events. If an event is catched a specific backend method is called.
I initialize the backend like the following. The method is called during the initialization of one of my Vaadin 14 views.
window.init = function(element) {
window.element = element;
...
}
View:
public class TestView extends Div {
public TestView() {
...
UI.getCurrent().getPage().executeJs("init($0)", this);
}
}
later on the methods are called with window.element.$server.onTestEvent();
on the frontend.
The called backend method:
@ClientCallable
private void onTestEvent() {
System.out.println("Test");
}
Now the issue:
I pass the view as element
.
If I change the view the element
I passed is destroyed so the event (on the backend side) can't be executed even if it is catched on the frontend.
Does Vaadin 14 provide a way to store objects "globally" over all views? I want the application to react on the events independent on which view I currently visit.
Upvotes: 1
Views: 332
Reputation: 4290
The easiest solution would be to use the element of a top-level main layout (view container / MainView) instead of individual views' elements.
Upvotes: 5