I know there are millions of questions like this, but they all come to having to call UI.getCurrent().access(…) and in my case UI.getCurrent() returns null. The same goes for VaadinSesscion.getCurrent() - also null. I am calling it from a Spring AsyncUncaughtExceptionHandler.
Basically, this is a bean that comes to life every time an exception occurs in an @Async annotated method (such as sending a mail). The handler thread is instantiated by Spring, so I have no way of passing it a Vaadin UI or Component.
So, is it possible to display any kind of error message to the user from a non-Vaadin thread?
There should at least be a way with JavaScript or such.
The component knows to which UI it has been attached to. A background thread is not attached to anything, thus UI.getCurrent() or VaadinSession.getCurrent() do not work there.
Thank you very much for your comment. I am not 100% sure I understand your example, but I cannot use getUI(), because my background thread has no access to the component it needs to be called on.
My question was meant to be specifically about using Spring’s @Async mechanism, where I have no control over the instantiation of the background thread.