Saturday, September 8, 2012

Tapestry Render Deferred Fixin


Tapestry5 pages consists of a set of components placed on this page. When client request comes to the server this components will render themselves in the same order they was placed on the page. The rendering of each component is divided into a number of phases (Component Rendering) but all this phases are triggered within its component rendering. So, what if there is a dependency of component-A in some setup logic of component-B? No problem, when their order is <component-B> => <component-A>. But what will happen if their order is <component-A> => <component-B>? Component-A will have invalid data from component-B(it hasn't initialized itself yet). There is a solution in Label component from tapestry-core. It defers "for" attribute rendering using Heartbeat service.

No problem, we can use similar code in our components too. But we can't use this in core tapestry components. Lets look to sample:

We have two components: event link and zone with some content. Event link should update only this zone, so it needs its id. But zone id is not generated during rendering of event link. Don't worry, we can use some piece of fixin-magic:

This fixin will render placeholder element instead of real component to remember where it should be placed. Then it will defer real component rendering using Heartbeat service. To use this fixin we just need to add it to our event link.

Live example
Source Code
Developing tapestry5 applications is quite simple.

No comments:

Post a Comment