Re: Recommended way to clean up a component?
"Geoff Longman" <[email protected]>
| Newsgroups | gmane.comp.java.tapestry.devel |
|---|---|
| Message-ID | <006301c28994$8c604640$1700a8c0@MOONBEAM> |
Recommended way to clean up a component?By looking at the Vlib example your following the pattern.
I would suggest that explicity registering a DetachListener should not be required. Could not the framework recognize that a component
implements PageDetachListener and just register it? That would save developers from having to override finishLoad().
Geoff
----- Original Message -----
From: Phil Surette
To: Tapestry Developer (E-mail)
Sent: Monday, November 11, 2002 9:30 AM
Subject: [Tapestry-developer] Recommended way to clean up a component?
I have some components that retrieve and store a copy of a db object in a local variable which is accessed many times by the component. The object is lazily loaded like this:
Object getCachedDBObject() {
if (m_cachedDBObject == null) {
m_cachedDBObject = retrieveObjectFromDB();
}
return m_cachedDBObject;
}
At the end of the current cycle, m_cachedDBObject needs to be nulled out so the next time the component is used it'll get a new copy.
What's the best way to do this? Right now I'm making my components implement PageDetachListener and override finishLoad() like this:
public finishLoad() {
getPage().addPageDetachListener(this);
}
public void pageDetached(PageEvent pageEvent){
m_cachedDBObject = null;
}
Is this the right way to do it? Is there a better way? I tried overriding cleanUpAfterRender but that didn't seem to work... could easily have been user error though.