Push, background thread and browser refresh

Hi All,

I am trying to update UI from a background thread and I am using Push functionality.
The way I do it is:

[code]
@Configurable
public class MyClassUI extends DocumentDesign {

private UI currentUI;

public MyClassUI() {
this.currentUI = UI.getCurrent();
}

public void myEventHandler(SomeEvent event) {
currentUI.access(new Runnable() {
@Override
public void run() {

}
});
}
[/code]Problem arises when user refreshes the UI - the old UI instance (this.currentUI) looses its VaadinSession instance and I get UIDetachedException exception. I understand that without PreserveOnRefresh annotation the UI gets “replaced” by a new one. But is there a way to hook up somehow to propagate that change of UI to my class which is then used by a background thread invoking myEventHandler method ? I would like to avoid the PreserveOnRefresh functionality …

Thanks,
Adrian

I think I have found a solution but if anybody knows a better way - please let me know :wink:
Since I am using spring boot integration for my app the UI instance ends up in spring container.
So what I only need to do now is:

MainUI mainUI = ApplicationContextProvider.getSpringApplicationContext().getBean(MainUI.class); mainUI.access(........ Thanks,
Adrian