answered
2015-12-09 04:34:54 +0800
cor3000 6280 ● 2 ● 7 I'd be careful with that, since according to the documentation there should only be one instance of a UiLifeCycle-listener. Which needs to be implemented in a thread safe way.
For that it's better to keep it stateless.
As an alternative you could add a callback as a component attribute to be called when the component detaches:
e.g. in your afterComponentDetached method
if(comp.hasAttribute("cleanupCallback")) {
Runnable callback = (Runnable)comp.getAttribute("cleanupCallback");
callback.run();
}
you can then register the callback where you create the component
Textbox mytext = new Textbox();
mytext.setAttribute("cleanupCallback", new Runnable() {
public void run() {
//do some cleanup here
}
});
for java 8
mytext.setAttribute("cleanupCallback", () -> {
//do some cleanup here
});
or
mytext.setAttribute("cleanupCallback", this::doCleanup);
...
public void doCleanup() {
//do some cleanup here
}