You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2009/02/17 10:02:54 UTC

t5: onActivate called twice

Hi,

I have following code, onActivate was called correctly 1st time, but it will
be called again during the rendering and obj[0] has 'images', obj[1]
has 'loading.gif', I do provide a onPassivate, any idea? thanks

   private Object[] _objs;

   @CommitAfter
   public Object onActivate(Object[] obj) {
       _objs = obj;
		if (_objs.length > 0) {
	            String id1 = (String) _obj[0];
				String id2 = (String) _obj[1];
	 	...
		return null
		} else return Other.class;
	}
	
	public Object[] onPassivate() {
        return _objs;
    }
 
-- 
View this message in context: http://www.nabble.com/t5%3A-onActivate-called-twice-tp22053148p22053148.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: onActivate called twice

Posted by dhning <ni...@gmail.com>.
You mean in rendering phase, onActivate is called twice? It is always called only one time in my experience.
I am interested in whether you called this page onActivate from other page?

DH


----- Original Message ----- 
From: "Angelo Chen" <an...@yahoo.com.hk>
To: <us...@tapestry.apache.org>
Sent: Tuesday, February 17, 2009 5:02 PM
Subject: t5: onActivate called twice


> 
> Hi,
> 
> I have following code, onActivate was called correctly 1st time, but it will
> be called again during the rendering and obj[0] has 'images', obj[1]
> has 'loading.gif', I do provide a onPassivate, any idea? thanks
> 
>   private Object[] _objs;
> 
>   @CommitAfter
>   public Object onActivate(Object[] obj) {
>       _objs = obj;
> if (_objs.length > 0) {
>             String id1 = (String) _obj[0];
> String id2 = (String) _obj[1];
> ...
> return null
> } else return Other.class;
> }
> 
> public Object[] onPassivate() {
>        return _objs;
>    }
> 
> -- 
> View this message in context: http://www.nabble.com/t5%3A-onActivate-called-twice-tp22053148p22053148.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
>

Re: t5: onActivate called twice

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Feb 17, 2009 at 9:30 AM, Angelo Chen <an...@yahoo.com.hk> wrote:
> You are correct, in one of my javascript it has a "../images/..", i don't
> know why it got called, in that particular page, there is no reference to
> that js, commenting it out fixes the problem, but this does bring up another
> question, how to put asset:context in a javascript?

One of the options is generating this piece of Javascript in a page or
component template. The other is using absolute URLs.

> what is event context? something like this:

EventContext is an interface from Tapestry:
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/EventContext.html.
You can use it in any event handler method:

Object onActivate(EventContext context) {
     if (context.getCount() == 0) {
        ....;
     }
}

> how to write a matching onPassivate for this?

Your onPassivate method can return an Object[] or a List.

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi,

You are correct, in one of my javascript it has a "../images/..", i don't
know why it got called, in that particular page, there is no reference to
that js, commenting it out fixes the problem, but this does bring up another
question, how to put asset:context in a javascript?

//var tb_pathToImage = "../images/loading.gif";        

// var tb_pathToImage = "${asset:context/images/loading.gif}";      // this
does not work

what is event context? something like this:
Object onActivate(String s1, String s2)
how to write a matching onPassivate for this?

Thanks,

Angelo



Thiago H. de Paula Figueiredo wrote:
> 
> Most probably you're including images in your page using relative
> paths. Use ${asset:context/images/loading.gif} instead and the problem
> goes away. ;)
> 
> By the way, use EventContext instead of Object[] as the parameter of
> your onActivate method. ;)
> 
> -- 
> Thiago
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-onActivate-called-twice-tp22053148p22056296.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by Peter Stavrinides <P....@albourne.com>.
Hi Angelo, 

I am probably over simplifying things, but think of it like this, Activate is analogous to a Get request, so is invoked when a page first loads, passivate is called after a Post (to ensure the posted page retains those activation parameters)... passivate does not correspond to activate in a 1:1 cycle, as posts can occur for any number of components / form events.

Cheers,
Peter



----- Original Message -----
From: "Thiago H. de Paula Figueiredo" <th...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Tuesday, 17 February, 2009 17:06:44 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Re: t5: onActivate called twice

On Tue, Feb 17, 2009 at 12:02 PM, Angelo Chen
<an...@yahoo.com.hk> wrote:

> you need a onPassivate to persist the context on the client side if:

You need an onPassivate() method to tell Tapestry what is the
activation context for a given page. This is needed primarily because
of redirect-after-post, AFAIK, and every time Tapestry needs to
generate a link for a page.

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Feb 17, 2009 at 12:02 PM, Angelo Chen
<an...@yahoo.com.hk> wrote:

> you need a onPassivate to persist the context on the client side if:

You need an onPassivate() method to tell Tapestry what is the
activation context for a given page. This is needed primarily because
of redirect-after-post, AFAIK, and every time Tapestry needs to
generate a link for a page.

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Thiago,

I just read again that doc, here is what I understand:

you need a onPassivate to persist the context on the client side if:

1. you have a form in the page
2. if you have an action link in the page

correct?

Angelo


Thiago H. de Paula Figueiredo wrote:
> 
> On Tue, Feb 17, 2009 at 10:28 AM, Angelo Chen
> <an...@yahoo.com.hk> wrote:
> 
>> Hi Thiago,
> 
> Hi!
> 
>> I always make sure i have a onPassivate that returns same thing in the
>> onActivate,
> 
> That's a good thing, returning the the save value, but not necessarily
> the same type.
> 
>> now, must be wrong, what is the rule of  thumb on this? why we
>> need a onPassivate?
> 
> There's a good explanation here:
> http://tapestry.apache.org/tapestry5/guide/pagenav.html.
> 
> -- 
> Thiago
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-onActivate-called-twice-tp22053148p22059004.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Feb 17, 2009 at 10:28 AM, Angelo Chen
<an...@yahoo.com.hk> wrote:

> Hi Thiago,

Hi!

> I always make sure i have a onPassivate that returns same thing in the
> onActivate,

That's a good thing, returning the the save value, but not necessarily
the same type.

> now, must be wrong, what is the rule of  thumb on this? why we
> need a onPassivate?

There's a good explanation here:
http://tapestry.apache.org/tapestry5/guide/pagenav.html.

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Thiago,

I always make sure i have a onPassivate that returns same thing in the
onActivate, now, must be wrong, what is the rule of  thumb on this? why we
need a onPassivate?

Thanks,

Angelo


Thiago H. de Paula Figueiredo wrote:
> 
> On Tue, Feb 17, 2009 at 10:16 AM, Angelo Chen
> 
> You cannot return an EventContext in the onPassivate method. You don't
> even need to return the same type you received in onActivate() in
> onPassivate(). If you want to return more than one paramenter in
> onPassivate(), return a List or an Object[].
> 
> -- 
> Thiago
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-onActivate-called-twice-tp22053148p22057321.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Feb 17, 2009 at 10:16 AM, Angelo Chen
<an...@yahoo.com.hk> wrote:

> Hi Thiago,

Hi, Angelo!


> Thanks for the tip, never knew there is this EventContext, is following
> onPassivate correct:

You cannot return an EventContext in the onPassivate method. You don't
even need to return the same type you received in onActivate() in
onPassivate(). If you want to return more than one paramenter in
onPassivate(), return a List or an Object[].

> What's the advantage of using EventContext compared to Object[], I know it
> is neat, any other reason?

It is type safe: take a look at its get() method. It uses the Tapestry
coercion feature to convert the value to the type you want. With an
Object[], all its elements are Strings and you have to do the
conversions yourself.

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Thiago,

Thanks for the tip, never knew there is this EventContext, is following
onPassivate correct:

private EventContext ec;

public Object onActivate(EventContext obj) {    ec = obj;}

public EventContext onPassivate() { return ec; }

What's the advantage of using EventContext compared to Object[], I know it
is neat, any other reason?

Thanks,

Angelo



Thiago H. de Paula Figueiredo wrote:
> 
> Most probably you're including images in your page using relative
> paths. Use ${asset:context/images/loading.gif} instead and the problem
> goes away. ;)
> 
> By the way, use EventContext instead of Object[] as the parameter of
> your onActivate method. ;)
> 
> -- 
> Thiago
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-onActivate-called-twice-tp22053148p22057115.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Most probably you're including images in your page using relative
paths. Use ${asset:context/images/loading.gif} instead and the problem
goes away. ;)

By the way, use EventContext instead of Object[] as the parameter of
your onActivate method. ;)

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: onActivate called twice

Posted by Angelo Chen <an...@yahoo.com.hk>.
btw, it is 5.0.18.


Angelo Chen wrote:
> 
> Hi,
> 
>  
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-onActivate-called-twice-tp22053148p22053292.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org