Hello!
I have this pice of code that update a grid almost every second or even more. It works all the time I can see the result in the UI however I also see how it throws and exception in the console com.vaadin.flow.component.UIDetachedException
@JmsListener(destination = "tick-channel", containerFactory = "jmsFactory")
public void receiveMessage(final Tick tick) {
this.tick = tick;
if (getUI().isPresent()) {
getUI().get().access(() -> {
try {
positionsList.forEach(p -> {
if (p.getSecurity().getSymbol().equals(tick.getSymbol().toUpperCase())) {
plMap.put(
p.getSecurity().getSymbol(),
formatColumnTypeNumber(positionService.calculatePL(p, tick.getClose(), BigDecimal.ZERO))
);
}
});
//TODO: fix that later not need it right now
} catch (Exception e) {
LOGGER.error(e);
}
});
positionGrid.getDataProvider().refreshAll();
}
}
This is probably caused by a message being delivered to an UI that is not attached anymore - in other words, the user closed the tab.
One way to avoid the issue is to listen to detach events from your UI and unregister it from receiving further messages.
You can also catch the exception when calling access and unregister it there.
In newer Flow versions, you can call accessLater(SerializableRunnable accessTask, SerializableRunnable detachHandler) instead. The detachHandler callback is then executed when the UI is detached, avoiding the exception.
it is a bit strange I am trying to reproduce the error, and by closing the tab … does not appears.
About the “One way to avoid the issue is to listen to detach events from your UI and unregister it from receiving further messages.” I guess you are speaking about:
But is not so clear for me what I should “Detach”… the getUI() ? I other hand I am looking for the method accessLater, but I have only “access”, I am using the version 11.0.2 right now.