Actually I received that advice several times. Although I know it's the one of the best workarounds for this problem, it's still bloated. I actually implemented my own listener logic that gets called from the top page's pageBeginRender() method, making my components implement an interface and calling their listeners in a cycle:

public void pageBeginRender(PageBeginRenderEvent e) {
   for(Component c : getComponents().values()) {
     if(c instanceof MyInitializationInterface) {
       ((MyInitializationInterface) c).onInit(...);
     }
   }
}

You still have to repeat this on all of your components, but at least it's cleaner than the lazy init pattern. It makes me wonder why Tapestry didn't implement this in the first plane. It could be actually faster.

(The lazy init pattern main problem is that you get lots of getXX() functions with unclear side effects - a big code smell IMO).

--
Ing. Leonardo Quijano Vincenzi
DTQ Software

Eric Schneider wrote:
Scott,

Yeah, this is a spot that can get a little awkward.

It feels most natural (maybe because of my WO experience) to allow the
page to init instance variables and pass them to components on the
page.   Where you hit a snag is when the component needs to init
additional things based on a parameter(s) passed into the component. The component's pageBeginRender() method is being called before page
is initialized and the parameter is passed to the component.   Bummer.
:-|

What I do is bag initializing components in pageBeginRender() and do
it lazily.  It's kind of a lamo pattern, but it hasn't gotten me in
trouble.

public abstract Object getMyObject();
public abstract void setMyObject(Object value);

public abstract Object getMyInflatedObject() {
   if (getMyObject() == null) {
       Object foo; // init my object, pg should be initialized, params passed
       setMyObject(foo);
   }
   return getMyObject();
}

In my .html/.jwc files I always reference the inflated method.

Hope that helps.
Cheers,
Eric



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to