Thanks for the suggestion, Adam. Yes, I have looked into this, and it
often helps -- but really what I'm trying to do is avoid all the lazy
initialization trickery of "has this field been initialized yet?"
That sort of thing gets messy, and in my experience doesn't even
always work right if you're looking for a field initialized by a form
component that won't be set until the component is rendered....
I just want a clear entry point for the initial display of a page. If
pages were POJOs, I could do something like this:
public class MyPage
implements PojoPage
{
public MyPage() // called when MyPage is requested from
PageService
{ ...default initialization...}
public MyPage(Thing toDisplay) // called from listeners in
other pages
{ ...initialization under a specific circumstance... }
}
In some other page:
public PojoPage someListener(...)
{
...
return new MyPage(thingToDisplay);
}
So I'm looking for some way to approximate this idea of calling
different constructors in different circumstances. Obviously, because
of pooling, that's not actually how pages work, but I still sort of
think of them in this OO-y way.
What I ended up doing was implementing IExternalPage in every single
page that has a "default" state, and treating activateExternalPage()
as the default constructor.
I even map .html to ExternalPageService (instead of PageService) in
my hivemodule.xml:
<contribution configuration-id="tapestry.url.ServiceEncoders">
<page-service-encoder id="external" extension="html"
service="external" />
<direct-service-encoder id="direct" stateless-
extension="direct" stateful-extension="sdirect" />
</contribution>
So my app doesn't really use PageService at all. This may be utterly
weird, but it's getting me where I want to go.
Comments on the approach are welcome.
Cheers,
Paul
On Aug 23, 2005, at 7:34 AM, Adam Greene wrote:
Have you thought implementing PageRenderListener
(PageBegnRenderListener in tapestry 4.0) in your class? That way
you can do the initialization just before the page renders (which
it will only do after the listener has been called and done it's
thing, so you can check to see if variables have already been
init'd by the listener).
The interface is org.apache.tapestry.events.PageRenderListener and
you simply put a call to addPageRenderListener(PageRenderListener
listener) in your Page constructor (at least that what I do, unless
someone has a better idea :-)
----- Original Message ----- From: "Paul Cantrell"
<[EMAIL PROTECTED]>
To: "Tapestry users" <[email protected]>
Sent: Thursday, August 18, 2005 2:16 PM
Subject: Initialization when called from PageService?
Is there a good way for a page to initialize itself if it's being
called from the page service?
A different way of asking this might be: is there a way to initialize
values only if no listeners are being called?
I have a few situations where values on the page are populated (in,
say, pageAttached()), then overwritten by a listener. That first
redundant initialization is expensive, and I'd rather not do it. But
it's of a sort that's awkward to implement using lazy initialization
in the property getter itself.
I could implement IExternalPage, and do my initialization in
activateExternalPage(). Is there something similar for PageService?
Or is IExternalPage really the right answer to my question?
Cheers,
Paul
_________________________________________________________________
"Les grandes personnes ne comprennent jamais rien toutes seules,
et c'est fatigant, pour les enfants, de toujours et toujours
leur donner des explications." -- Antoine de Saint-Exupéry
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
"Prediction is hard, especially of the future." -- Niels Bohr
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]