Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin CDI: UIScoped bean not calling @PreDestroy on UI destruction
Am I assuming something i shouldn't? What i tried is the following:
I have a pojo called UserSession, annotated with @NormalUIScoped. When a user logs in, i set his info to the pojo. On the @PostConstruct, everything works as expected. However, i had a method invocation on my @PreDestroy method that was never being called. I added some logger calls on the first line of the @PreDestroy method, and still was never called. I found it quite weird, i tried destroying the UI by logging out (log out closes the vaadin session and reload the current page), by setting a timeout of 2min on web.xml, and finally by closing the browser tab. In all cases the UI was destroyed but the @PreDestroy was never invoked. I found that pretty weird, since the UIScoped annotation is very explicit about the lifecyle of the annotated bean.
In light of that, i decided to replace the @PreDestroy method with something different, just for the sake of testing. I implemented the ClientConnector.DetachListener interface on the UserSession pojo, and on the @PostConstruct method i added a line to register it in the UI, and it worked like a charm.
UI.getCurrent().addDetachListener( this );
So, i come back to my first question, Am I assuming something i shouldn't? Did I interpret the UIScoped lifecyle wrong? Or should it actually be working but it's not?
If it helps, my project is running Vaadin 7.5.9, Vaadin CDI 1.0.3, Weld Servlet 2.3.3.Final and one of the subprojects has DeltaSpike 1.5.4 (I mention this because i know vaadin cdi has a dependency on deltaspike 1.4.something)