Re: [T5]: how to prevent onActivate() from firing with activationcontext
This feels a little kludgy, but you can always use a signal that is reset at some time after the activation. syncLists would then just check that boolean signal to see if it had already been run. Alternately, If you have a spring-style prototype scope in your services (ie, created anew for each injection) then you can move syncLists into a prototyped service so that it is, itself, a new instance for each inject. Then syncLists() on that service can call internal (hidden) signalling to ensure it is only called once per lifetime. The latter is a bit of extra infrastructure, but I have often used prototype-scope to get one-shot behaviour like this. If you have other need of this same scope, then it can be useful. Christian. On 24-Oct-07, at 5:39 AM, Britske wrote: for a page, I have two activation-methods: onActivate() onActivate(Object[] list); when i provide an activation context to the page both methods are called -onactivate() first-. This seems correct behavior according to some forum-posts i've read. However, both methods call a method syncLists() which does a pretty expensive operation (get search results based on the activation context or default if no activation context exists). The problem is that now syncLists() is called twice when the page has an activation-context (based on calling both of the onActivate()- methods). Obviously this is unwanted. However, I can't remove syncLists() from onActivate() (without params), because a page-access without activation-context should call syncLists() as well. so what i need to do is a. have onActivate() not called when an activatecontext exists b. detect in onActivate() that an activationcontext exists and based on that not call syncLists(). c. don't have syncLists() updated on onActivate() but on a change of the page (so before the "redirect-after-post") I can't find a way to do A. or B. while C. doesn't seem the best option, because a lot of fields (on the page and in components) would need to be tagged with @Persist to survive setting them on post and then redirecting. Anyone? Thanks, Geert-Jan -- View this message in context: http://www.nabble.com/-T5-%3A-how-to-prevent-onActivate%28%29-from-firing-with-activationcontext-tf4683298.html#a13382460 Sent from the Tapestry - User mailing list archive at Nabble.com. - 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]: how to prevent onActivate() from firing with activationcontext
Make that: onActivate(Object[] list) { if(params==null || params!=list) //actually a method doing a compare on the elements of the list { //handle context params = list; } } Britske wrote: > > Thanks, removed the onActivate() without params. > > Moreover, i didn't test fully and discovered that on a post onActivate is > called once with the context of the old page and once with the context of > the new page, so it's not always empty the first time. Probably saying the > obvious but anyway.. Only in the latter case should the onActivate result > in update of my lists. > > for that i have the following to track the current activation-context > > @Persist Object[] params; > > now i do: > > onActivate(Object[] list) > { > if(params!=list) //actually a method doing a compare on the elements of > the list > { >//handle context >params = list; > } > } > > thanks for helping me in the right direction, > Geert-Jan > > > > Nick Westgate wrote: >> >> I'm not going to delve into the logic of your use case. >> Just put have one activate handler: >> >> void onActivate(Object[] context) >> { >> if (context.length == 0) >> { >> // handle no context >> { >> else >> { >> // handle context >> { >> } >> >> Cheers, >> Nick. >> >> >> Britske wrote: >>> for a page, I have two activation-methods: >>> >>> onActivate() >>> onActivate(Object[] list); >>> >>> when i provide an activation context to the page both methods are called >>> -onactivate() first-. >>> This seems correct behavior according to some forum-posts i've read. >>> >>> However, both methods call a method syncLists() which does a pretty >>> expensive operation (get search results based on the activation context >>> or >>> default if no activation context exists). >>> >>> The problem is that now syncLists() is called twice when the page has an >>> activation-context (based on calling both of the onActivate()-methods). >>> Obviously this is unwanted. >>> >>> However, I can't remove syncLists() from onActivate() (without params), >>> because a page-access without activation-context should call syncLists() >>> as >>> well. >>> >>> so what i need to do is >>> a. have onActivate() not called when an activatecontext exists >>> b. detect in onActivate() that an activationcontext exists and based on >>> that >>> not call syncLists(). >>> c. don't have syncLists() updated on onActivate() but on a change of the >>> page (so before the "redirect-after-post") >>> >>> I can't find a way to do A. or B. while C. doesn't seem the best option, >>> because a lot of fields (on the page and in components) would need to be >>> tagged with @Persist to survive setting them on post and then >>> redirecting. >>> >>> Anyone? >>> >>> Thanks, >>> Geert-Jan >> >> - >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> > > -- View this message in context: http://www.nabble.com/-T5-%3A-how-to-prevent-onActivate%28%29-from-firing-with-activationcontext-tf4683298.html#a13384953 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T5]: how to prevent onActivate() from firing with activationcontext
Thanks, removed the onActivate() without params. Moreover, i didn't test fully and discovered that on a post onActivate is called once with the context of the old page and once with the context of the new page, so it's not always empty the first time. Probably saying the obvious but anyway.. Only in the latter case should the onActivate result in update of my lists. for that i have the following to track the current activation-context @Persist Object[] params; now i do: onActivate(Object[] list) { if(params!=list) //actually a method doing a compare on the elements of the list { //handle context params = list; } } thanks for helping me in the right direction, Geert-Jan Nick Westgate wrote: > > I'm not going to delve into the logic of your use case. > Just put have one activate handler: > > void onActivate(Object[] context) > { > if (context.length == 0) > { > // handle no context > { > else > { > // handle context > { > } > > Cheers, > Nick. > > > Britske wrote: >> for a page, I have two activation-methods: >> >> onActivate() >> onActivate(Object[] list); >> >> when i provide an activation context to the page both methods are called >> -onactivate() first-. >> This seems correct behavior according to some forum-posts i've read. >> >> However, both methods call a method syncLists() which does a pretty >> expensive operation (get search results based on the activation context >> or >> default if no activation context exists). >> >> The problem is that now syncLists() is called twice when the page has an >> activation-context (based on calling both of the onActivate()-methods). >> Obviously this is unwanted. >> >> However, I can't remove syncLists() from onActivate() (without params), >> because a page-access without activation-context should call syncLists() >> as >> well. >> >> so what i need to do is >> a. have onActivate() not called when an activatecontext exists >> b. detect in onActivate() that an activationcontext exists and based on >> that >> not call syncLists(). >> c. don't have syncLists() updated on onActivate() but on a change of the >> page (so before the "redirect-after-post") >> >> I can't find a way to do A. or B. while C. doesn't seem the best option, >> because a lot of fields (on the page and in components) would need to be >> tagged with @Persist to survive setting them on post and then >> redirecting. >> >> Anyone? >> >> Thanks, >> Geert-Jan > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/-T5-%3A-how-to-prevent-onActivate%28%29-from-firing-with-activationcontext-tf4683298.html#a13384950 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T5]: how to prevent onActivate() from firing with activationcontext
I'm not going to delve into the logic of your use case. Just put have one activate handler: void onActivate(Object[] context) { if (context.length == 0) { // handle no context { else { // handle context { } Cheers, Nick. Britske wrote: for a page, I have two activation-methods: onActivate() onActivate(Object[] list); when i provide an activation context to the page both methods are called -onactivate() first-. This seems correct behavior according to some forum-posts i've read. However, both methods call a method syncLists() which does a pretty expensive operation (get search results based on the activation context or default if no activation context exists). The problem is that now syncLists() is called twice when the page has an activation-context (based on calling both of the onActivate()-methods). Obviously this is unwanted. However, I can't remove syncLists() from onActivate() (without params), because a page-access without activation-context should call syncLists() as well. so what i need to do is a. have onActivate() not called when an activatecontext exists b. detect in onActivate() that an activationcontext exists and based on that not call syncLists(). c. don't have syncLists() updated on onActivate() but on a change of the page (so before the "redirect-after-post") I can't find a way to do A. or B. while C. doesn't seem the best option, because a lot of fields (on the page and in components) would need to be tagged with @Persist to survive setting them on post and then redirecting. Anyone? Thanks, Geert-Jan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[T5]: how to prevent onActivate() from firing with activationcontext
for a page, I have two activation-methods: onActivate() onActivate(Object[] list); when i provide an activation context to the page both methods are called -onactivate() first-. This seems correct behavior according to some forum-posts i've read. However, both methods call a method syncLists() which does a pretty expensive operation (get search results based on the activation context or default if no activation context exists). The problem is that now syncLists() is called twice when the page has an activation-context (based on calling both of the onActivate()-methods). Obviously this is unwanted. However, I can't remove syncLists() from onActivate() (without params), because a page-access without activation-context should call syncLists() as well. so what i need to do is a. have onActivate() not called when an activatecontext exists b. detect in onActivate() that an activationcontext exists and based on that not call syncLists(). c. don't have syncLists() updated on onActivate() but on a change of the page (so before the "redirect-after-post") I can't find a way to do A. or B. while C. doesn't seem the best option, because a lot of fields (on the page and in components) would need to be tagged with @Persist to survive setting them on post and then redirecting. Anyone? Thanks, Geert-Jan -- View this message in context: http://www.nabble.com/-T5-%3A-how-to-prevent-onActivate%28%29-from-firing-with-activationcontext-tf4683298.html#a13382460 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]