Search code examples
javatapestry

Tapestry - Composite components?


can somebody tell me how to create composite components in Tapestry? I know how to do this in JSF with using as well as ui:define. But how with tapestry?

I'd like to create following setup:

sidebar.tml: should define some replaceable variables, here 'header' and 'content'

<t:container>
The header is ${header}, and the content ist ${content}.
</t:container>

layout.tml: should define the right place for the sidebar to always align to

//header
<t:sidebar /> 
//footer

customPage.tml: should deliver the content for the sidebar

<t:sidebar>
    <t:header>my header</t:header>
    <t:content>some content here</t:content>
</t:sidebar>

I know is cannot be done this way, but I hope you understand what I'm trying to do and could help me?

tyvm


Solution

  • This is how I'd do it:

    sidebar.tml

    <t:container>
    The header is <t:delegate to="header"/>, and the content ist <t:delegate to="content"/>
    </t:container>
    

    Sidebar.java

    public class Sidebar
    {
        @Property
        @Parameter(required = true)
        private Block header;
    
        @Property
        @Parameter(required = true)
        private Block content;
    

    layout.tml

    //header
    <t:sidebar header="sidebarHeader" content="sidebarContent"/> 
    //footer
    

    Layout.java

    public class Layout
    {
        @Property
        @Parameter(required = true)
        private Block sidebarHeader;
    
        @Property
        @Parameter(required = true)
        private Block sidebarContent;
    

    customPage.tml

    <t:layout>
        <p:sidebarHeader>my header</p:sidebarHeader>
        <p:sidebarContent>some content here</p:sidebarContent>
        rest of your content here
    </t:layout>
    

    Hope it helps!