Tapestry 5: Rendering a Block in a page
This one took awhile to figure out. In Tapestry, if a component is passed to another component (such as your main page layout component), you need to pass it as a Block parameter. The problem with blocks, there is no quick way to render them. You can use the @AfterRenderBody rendering stage annotation, but this gives you very limited flexibility in where the object will end up (or you make kludgy hacks to put this together).
This quick little component can solve all those problems. I present you Render.java. This incredible class is appearing in IRM 2.
Update: You can also use the builtin Tapestry component named Delegate.
<t:delegate to="block:foo"/>
But if you still prefer, you can use this Component:
package net.stackworks.irm.web.components; import org.apache.tapestry.annotations.Parameter;/** * Simple component which will render a Block in a page. * To use: - Make sure your Block has a defined getter method (getSidebar()) which returns the Block * - Do a <t:render value="sidebar"/> <!-- this calls getSidebar() --> * - Enjoy your rendered Block * @author Yann Ramin * */ public class Render { @Parameter(required = true) private Object _value; /** * Returns the Object, which allows another object (presumably, a block) to render * first. * * @return Object to render */ Object beginRender() { return _value; } }
Hello Sir,
How can i set a default value in ?
My Application use but i cannot set its default value.
I need to click a button in order to view its page.
Comment by alan earl — November 11, 2009 @ 12:51 am
try to use zone with delegate inside it.
Zone can be set with default.
Good Luck…
Comment by alanearl — November 26, 2009 @ 2:06 am
ок славно
Comment by нормы установки газовых котлов — June 17, 2010 @ 2:22 am