Would it be possible for you to share that code with us? I don't necessarily want to use that approach, but it would be very helpful to see how you implemented it.
Inge On Tue, Dec 8, 2009 at 9:10 AM, DH <ningd...@gmail.com> wrote: > Once I found it difficult too, and I never used EventContext because I > think it is not better than multiple onActivate. > > Finally I wrote my own PageActivationContext called PageActivationUnit, the > difference is that PageActivationContext only can occur once, but > PageActivationUnit can be used in multiple fields. > > For example, a product search page, it has params like > category,keyword,pagesize,pageno,brand and so on. If using > PageActivationUnit, the java would be like: > > @PageActivationUnit > private Category category; > > @PageActivationUnit > private String keyword; > > @PageActivationUnit > private Integer pagesize; > > @PageActivationUnit > private Integer pageNo; > > @PageActivationUnit > private Brand brand; > > PageActivationUnit will handle all the activate and passivate event for me, > and the url requested would be like > '/searchpage/category-value/keyword-value/pagesize-10/pageNo-2/brand-value'. > Yes, I encode the field name in the url and its value in a pair. > Another advantage is if later another param 'orderBy' is added, I don't > have to change any code at all. > > DH > http://www.gaonline.com.cn > > ----- Original Message ----- > From: "Kalle Korhonen" > To: "Tapestry users" <users@tapestry.apache.org> > Sent: Tuesday, December 08, 2009 2:22 PM > Subject: Best practice for initializing page to default context > > > > Most things in T5 are delightfully simple, but I find this > > surprisingly difficult: how to best initialize a page to default > > context (and redirect to it). Imagine you have a search & result page. > > If I access the page without any context I want all records to be > > displayed. In onActivate() without parameters I set the context to > > *all* and return this to redirect, then I query the database in > > setupRender() to initialize the data for the grid. However, sorting > > the grid will also cause a call to onActivate() without parameters, > > resetting my data to the default context. The parameter-less call to > > onActivate() would be harmless if I didn't do a redirect from > > onActivate() but then I cannot set the default context and redirect. > > In setupRender() I could decide whether redirect is needed or not but > > at that time, I'm already committed to rendering the request. > > > > Because events cause a parameterless onActivate() call, I tend to > > reserve onActivate() for possible component/event initialization needs > > only and always link to pages with initial context already set. I also > > find it roughly impossible to use overloaded versions of onActivate() > > and subsequently, if my page has multiple entry points, I typically > > resort to implementing it in a single onActivate(EventContext > > eventContext) operation containing a big if-else clause. Since the > > activation context is anyway sent with an event request (as in > > ?t:ac=mycontext), rather than using the encoded context for rendering, > > wouldn't it be just simpler if that context was used for activating > > the page for the event request and the following redirect for > > rendering would just use whatever context onPassivate() returns? What > > do others think, how do you handle this? > > > > Kalle > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > > For additional commands, e-mail: users-h...@tapestry.apache.org > > > > >