Re: T5: onActivate called twice
Already pointed out that this is expected. But you can bypass this behavior. Make your two-parameter method return "true" on successful processing; then your 1-parameter method won't be called. Robert On Mar 25, 2009, at 3/256:10 AM , Peter Kanze wrote: Hello I have a pagelink that point to this /products/computer/5 In my Products.java I have two onActivate methods. See below. When I click the pageLink I can see that both onActivate are called. Because this is printed to the output console: onActivate(String categoryName, int pageNr) onActivate: (String categoryName) Can somebody explain this? I would expect only public void onActivate(String categoryName, int pageNr) to be called, because the context has 2 parameters. greetz, Peter public void onActivate(String categoryName) { System.out.println("onActivate: (String categoryName)"); } public void onActivate(String categoryName, int pageNr) { System.out.println("onActivate(String categoryName, int pageNr)"); } - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: T5: onActivate called twice
As Andy already pointed, this is normal Tapestry behaviour. When you have more than onActivate() method, I recommend the use of a single method receiving an EventContext (http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/EventContext.html): onActivate(EventContext event) { if (event.getCount() == 1) { String categoryName = event.get(String.class, 0); } if (event.getCount() == 2) { String categoryName = event.get(String.class, 0); int pageNumber = event.get(Integer.class, 1); } } -- Thiago - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
RE: T5: onActivate called twice
Taken from http://tapestry.apache.org/tapestry5.1/guide/event.html and should answer your question I think. Multiple Method Matches In some cases, you may have multiple event methods match a single event. The order is as follows: * Base class methods before sub-class methods. * Matching methods within a class in alphabetical order. * For a single method name with multiple overrides, by number of parameters, descending. There's only rare cases where it makes sense for more than one method to handle an event. When a sub-class overrides an event handler method of a base class, the event handler method is only invoked once, along with any other base class methods. The subclass can change the implementation of the base class method via an override, but can't change the timing of when that method is invoked. See TAPESTRY-2311. > -Original Message- > From: Peter Kanze [mailto:peterka...@gmail.com] > Sent: 25 March 2009 11:11 > To: Tapestry users > Subject: T5: onActivate called twice > > Hello > I have a pagelink that point to this /products/computer/5 > > In my Products.java I have two onActivate methods. See below. > When I click the pageLink I can see that both onActivate are called. > Because this is printed to the output console: > > onActivate(String categoryName, int pageNr) > onActivate: (String categoryName) > > Can somebody explain this? > I would expect only public void onActivate(String categoryName, int > pageNr) > to be called, because the context has 2 parameters. > > greetz, > Peter > > > public void onActivate(String categoryName) { > System.out.println("onActivate: (String categoryName)"); > } > public void onActivate(String categoryName, int pageNr) { > System.out.println("onActivate(String categoryName, int pageNr)"); > } - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
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" To: "Tapestry users" 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 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
On Tue, Feb 17, 2009 at 12:02 PM, Angelo Chen 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
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 > 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-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
On Tue, Feb 17, 2009 at 10:28 AM, Angelo Chen 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
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-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
On Tue, Feb 17, 2009 at 10:16 AM, Angelo Chen 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
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-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
On Tue, Feb 17, 2009 at 9:30 AM, Angelo Chen 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
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-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: onActivate called twice
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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: T5: onActivate() called twice
What version of Tapestry? This was addressed in 5.0.14, I believe, to ensure that when overriding a base class event handler method, the method is not invoked twice. On Mon, Apr 21, 2008 at 6:25 AM, Leon Derks <[EMAIL PROTECTED]> wrote: > Hi Davor, > > Indeed, I have a BasePage that implements the public void onActivate() > {}method. > > In my subpage I also have implemented the public void onActivate() {}. > The code in onActivate() of my subpage is executed twice. > > BASEPAGE: > public void onActivate() { > String pageName = resources.getPageName(); > breadCrumbHolder.checkBreadCrumbForRemove(pageName); > } > > SUBCLASS: > public void onActivate() { > logger.debug("OnActivate "); > products = productDAO.findAllByCategory(ProductCategory.Books); > if (logger.isDebugEnabled()) { > logger.debug("Nr of products: " + products.size()); > } > } > > This is the logging when I acces the page: > > [DEBUG] Products OnActivate > [DEBUG] Products Nr of products:: 43 > [DEBUG] Products OnActivate > [DEBUG] Products Nr of products:: 43 > > Leon > > Davor Hrg wrote: >> >> you have to be more specific, >> >> same OnActivate method will not be called more than once in normal >> circumastances, >> >> but overriding onActivate from a base class I belive can cause this ... >> >> some code would be useful. >> >> Davor Hrg >> >> On Mon, Apr 21, 2008 at 12:41 PM, Leon Derks <[EMAIL PROTECTED]> >> wrote: >> >> >>> >>> Hi, >>> >>> I noticed that my onActivate() is called twice. >>> >>> I solved the problem by changing onActivate() into onActivate(Object[] >>> parameters). >>> >>> Now it is only called once. But is this the way to do this or is there a >>> better way? >>> >>> greetings, >>> Leon >>> >>> >>> >>> - >>> 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] > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: T5: onActivate() called twice
Hi Leon, I am facing the same problem with the onActivate() method calling twice. Did you find any solution for this? Thanks, Yees. -Original Message- From: Leon Derks [mailto:[EMAIL PROTECTED] Sent: Monday, April 21, 2008 6:56 PM To: Tapestry users Subject: Re: T5: onActivate() called twice Hi Davor, Indeed, I have a BasePage that implements the public void onActivate() {}method. In my subpage I also have implemented the public void onActivate() {}. The code in onActivate() of my subpage is executed twice. BASEPAGE: public void onActivate() { String pageName = resources.getPageName(); breadCrumbHolder.checkBreadCrumbForRemove(pageName); } SUBCLASS: public void onActivate() { logger.debug("OnActivate "); products = productDAO.findAllByCategory(ProductCategory.Books); if (logger.isDebugEnabled()) { logger.debug("Nr of products: " + products.size()); } } This is the logging when I acces the page: [DEBUG] Products OnActivate [DEBUG] Products Nr of products:: 43 [DEBUG] Products OnActivate [DEBUG] Products Nr of products:: 43 Leon Davor Hrg wrote: > you have to be more specific, > > same OnActivate method will not be called more than once in normal > circumastances, > > but overriding onActivate from a base class I belive can cause this ... > > some code would be useful. > > Davor Hrg > > On Mon, Apr 21, 2008 at 12:41 PM, Leon Derks <[EMAIL PROTECTED]> wrote: > > >> Hi, >> >> I noticed that my onActivate() is called twice. >> >> I solved the problem by changing onActivate() into onActivate(Object[] >> parameters). >> >> Now it is only called once. But is this the way to do this or is there a >> better way? >> >> greetings, >> Leon >> >> >> >> - >> 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] DISCLAIMER: --- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any mail and attachments please check them for viruses and defect. --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: T5: onActivate() called twice
Hi Davor, Indeed, I have a BasePage that implements the public void onActivate() {}method. In my subpage I also have implemented the public void onActivate() {}. The code in onActivate() of my subpage is executed twice. BASEPAGE: public void onActivate() { String pageName = resources.getPageName(); breadCrumbHolder.checkBreadCrumbForRemove(pageName); } SUBCLASS: public void onActivate() { logger.debug("OnActivate "); products = productDAO.findAllByCategory(ProductCategory.Books); if (logger.isDebugEnabled()) { logger.debug("Nr of products: " + products.size()); } } This is the logging when I acces the page: [DEBUG] Products OnActivate [DEBUG] Products Nr of products:: 43 [DEBUG] Products OnActivate [DEBUG] Products Nr of products:: 43 Leon Davor Hrg wrote: you have to be more specific, same OnActivate method will not be called more than once in normal circumastances, but overriding onActivate from a base class I belive can cause this ... some code would be useful. Davor Hrg On Mon, Apr 21, 2008 at 12:41 PM, Leon Derks <[EMAIL PROTECTED]> wrote: Hi, I noticed that my onActivate() is called twice. I solved the problem by changing onActivate() into onActivate(Object[] parameters). Now it is only called once. But is this the way to do this or is there a better way? greetings, Leon - 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]
Re: T5: onActivate() called twice
you have to be more specific, same OnActivate method will not be called more than once in normal circumastances, but overriding onActivate from a base class I belive can cause this ... some code would be useful. Davor Hrg On Mon, Apr 21, 2008 at 12:41 PM, Leon Derks <[EMAIL PROTECTED]> wrote: > Hi, > > I noticed that my onActivate() is called twice. > > I solved the problem by changing onActivate() into onActivate(Object[] > parameters). > > Now it is only called once. But is this the way to do this or is there a > better way? > > greetings, > Leon > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >