You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Dmitry I. Zubarovsky" <au...@rambler.ru> on 2004/04/29 10:48:28 UTC
Re[2]: Page/component initialization complicated?
Hello Vjeran,
What about using such an approach.
Code from VLib
you page must implements this,
public interface IActivate extends IPage
{
public void activate(IRequestCycle cycle);
}
implementation:
public void activate(IRequestCycle cycle){
init(); //<-- put your initialization here
cycle.activate(this);
}
//when you need to go to your page with initialization, do the following
activatePage = (IActivate)cycle.getPage("pagename");
activatePage.activate(cycle);
Hope this helps
Regards,
Dima
VM> No good.
VM> I am looking for *true* initialization method which would be called only
VM> *once*, not pageBeginRender() method which gets called twice when using
VM> forms (during rewind and render phase).
VM> As I can see till now, the only way to set and reset some instance variable
VM> for duration of request is pretty cumbersome -
VM> I have to implement 2 interfaces, PageRenderListener and PageDetachListener,
VM> and I have to fill them as following:
VM> private Foo foo;
VM> public void pageBeginRender(PageEvent event) {
VM> if (foo == null) {
VM> foo = new Foo();
VM> }
VM> }
VM> public void pageEndRender(PageEvent event) {
VM> }
VM> public void pageDetached(PageEvent event) {
VM> foo = null;
VM> }
VM> -Vjeran
VM> ----- Original Message -----
VM> From: "Robert Zeigler" <rd...@u.arizona.edu>
VM> To: "Tapestry users" <ta...@jakarta.apache.org>
VM> Sent: Thursday, April 29, 2004 9:31 AM
VM> Subject: Re: Page/component initialization complicated?
>> Implement the PageRenderListener interface, and put your code in the
>> pageBeginRender() method.
>> eg:
>> private Foo var;
>> //a property defined in the page specification...
>> public abstract Bar getBar();
>> public abstract void setBar(Bar b);
>> public void pageBeginRender(PageEvent event) {
>> var = new Foo();
>> setBar(new Bar());
>> }
>>
>> Robert
>>
>>
>>
>> Vjeran Marcinko wrote:
>>
>> >Hi.
>> >
>> >Is there some method where I can put some page/component initialization
>> >logic that will be called *once at the beggining of each request* ? I
VM> don't
>> >care if page/component is newly instantiated, or fetched from pool, I
VM> don't
>> >care if request processing is starting with rewind phase or render
VM> phase...
>> >I just want it to be called at the beginning of each request ?
>> >
>> >End of request is easy - PageDetachListener is for that (actually it's
VM> about
>> >returning to pool, but it's the same thing since it happens at the end of
>> >request).
>> >
>> >Something like :
>> >
>> >public void requestStarted() {
>> > var = new Foo();
>> >}
>> >
>> >public void requestEnded() { // this can be achieved by pageDetached()
VM> or
>> >initialize()
>> > var = null;
>> >}
>> >
>> >Regards,
>> >Vjeran
VM> ---------------------------------------------------------------------
VM> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
VM> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
--
Best regards,
Dmitry mailto:aurox@rambler.ru
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org