【问题标题】:Tapestry - Composite components?Tapestry - 复合组件?
【发布时间】:2012-04-24 22:57:28
【问题描述】:

谁能告诉我如何在 Tapestry 中创建复合组件? 我知道如何在 JSF 中使用 using 以及 ui:define 来做到这一点。 但是挂毯呢?

我想创建以下设置:

sidebar.tml: 应该定义一些可替换的变量,这里是'header'和'content'

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

layout.tml: 应该定义侧边栏始终对齐的正确位置

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

customPage.tml: 应该为侧边栏提供内容

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

我知道不能这样做,但我希望你能理解我想要做什么并且可以帮助我吗?

tyvm

【问题讨论】:

    标签: java tapestry


    【解决方案1】:

    这就是我的做法:

    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
    

    布局.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>
    

    希望对你有帮助!

    【讨论】:

    • 嗯,不错!但我只得到字符串输出“sidebarHeader”和“sidebarContent”。它不会被 customPage 内容中的标签替换。
    • 默认情况下您似乎以某种方式使用“文字”绑定前缀。更改您的参数以改用“prop”绑定前缀。像这样:@Parameter(defaultPrefix = BindingConstants.PROP)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多