-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@PreDestroy not called on View Scope? #1355
Comments
@javaserverfaces Commented |
@javaserverfaces Commented |
@javaserverfaces Commented http://forums.java.net/jive/thread.jspa?threadID=67603&tstart=0 |
@javaserverfaces Commented |
@javaserverfaces Commented |
@javaserverfaces Commented |
@javaserverfaces Commented If you exit the page with an <h:command link, it calls the bean's PreDestroy I think in my case I would run the risk of accumulating dead diagrams which |
@javaserverfaces Commented Essentially, this is expected behavior. Imagine a case where you have multiple tabs open, or press the back button - in This means that if you also do <h:link> this will also be the behavior. The views will all be reaped when the session expires, of course, which is often There's also a configurable limit to the number of views - 15 is the default, Ed Burns had said when I asked this that he'd also like to think about this Sorry it took so many iterations for you to get your answer, but I'm afraid that |
@javaserverfaces Commented |
@javaserverfaces Commented |
@javaserverfaces Commented |
@javaserverfaces Commented |
|
Possible unconfirmed error reported on the forums:
I have a managed bean that needs to remove its data listener from an
ApplicationScoped data model, and I would like to put the managed bean in View
scope. So I need to know when its lifespan is up.
I naively thought that ViewScoped managed beans expire when I change to a
different page in the browser, but I see that it's not so simple. If I then use
the browser's back (or forward) button the view is still there, maintaining its
state. I was also a little surprised to see that the ViewScoped bean survives
destroying the session.
Anyway, I put a method with a @PreDestroy annotation on the ViewScoped bean, and
also registered a ComponentSystemEventListener on the view root for
PreDestroyViewMap events.
In the server logs, I see it create new instances of my bean when I reload the
page or follow a link to it, but I have never seen either the PreDestroy method
or the listener called. (The PostConstruct method DOES get called).
Am I confused, is there a bug, or do they just live forever? Or is there another
way to find out when they expire? Is it possible to have more than one
UIViewRoot on the same page concurrently in one session? What triggers their
expiration? I haven't found much detail on this, so if anyone knows of any doc,
please let me know.
Here's my code for registering the listener. I tried calling it in the bean's
constructor and in the PostConstruct method, which does get called.
private void registerViewListener() {
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = context.getViewRoot();
viewRoot.subscribeToEvent(PreDestroyViewMapEvent.class, new ViewMapExitHandler());
}
public class ViewMapExitHandler
implements ComponentSystemEventListener, Serializable {
public ViewMapExitHandler() {}
public void processEvent (ComponentSystemEvent event) {
System.out.println("ViewMapExitHandler");
diagram.setDataModel(null);
event.getComponent().unsubscribeFromEvent(PreDestroyViewMapEvent.class, this);
}
}
Thanks for any help.
Environment
Operating System: All
Platform: All
Affected Versions
[2.0.0-RC1]
The text was updated successfully, but these errors were encountered: