Dear Wiki user, You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.
The following page has been changed by 5451vs5451: http://wiki.apache.org/tapestry/Tapestry5SimpleAndPowerfulLayouts New page: Here, we are going to create a simple and reusable component, which makes it extremely easy to create layout components. First, we create a "Slot" component. It is used as a placeholder in our layout components. Slot.java : {{{#!java package org.myorg.t5demo.components; import org.apache.tapestry5.BindingConstants; import org.apache.tapestry5.Block; import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.ioc.annotations.Inject; public class Slot { @Inject private ComponentResources resources; @Parameter(name = "id", defaultPrefix = BindingConstants.LITERAL, required = true) private String id; Object beginRender() throws Exception { ComponentResources res = resources.getContainerResources(); Block toRender = null; while (res != null) { Block temp = res.findBlock(id); if (temp != null) { toRender = temp; } res = res.getContainerResources(); } return toRender; } } }}} Now, we create a layout component, Layout.tml {{{ <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> <head></head> <body> <h1>DefaultLayout</h1> <t:Slot id="part1"></t:slot> <t:Slot id="part2"></t:slot> </body> </html> }}} and use it to create a page. Index.tml {{{ <html t:type="SecondaryLayout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> <t:block id="part2"> <h1>${part2}</h1> </t:block> </html> }}} index.java : {{{#!java package org.myorg.t5demo.pages; public class Index { public String getPart2() { return "Part 2"; } } }}} Now, try it yourself. Note that we do not have a single line of java code to handle layouting logic. And also note that we do not have to add a block in the page for each slot defined in the layout component. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
