【问题标题】:How to set a define inside other define如何在其他定义中设置定义
【发布时间】:2011-01-05 12:28:42
【问题描述】:

我正在用 jboss、seam、richfaces 开发一个 Web 应用程序。

我使用模板(xhtml)作为所有其他人的母版页,并在那里设置了两个插入标签。 <ui:insert name="head"/> <ui:insert name="body"/>

问题是在使用此母版页作为模板的页面中,<ui:define name="head">...</ui:define> 必须在 <ui:define name="body">...</ui:define> 内定义。

我该怎么做?

基本上,我想要做的是:

<ui:define name="body">... <ui:define name="head"> <meta name="title" content="#{something.title}" /> </ui:define> ...</ui:define>

母版页必须返回:<meta name="title" content="#{something.title}" /><ui:insert name="head"/>

提前致谢

【问题讨论】:

  • 为什么要嵌套 ui:define 标签?很有可能,你只是认为你做到了。

标签: jsf richfaces seam


【解决方案1】:

您可以使用<ui:param> 在每个页面上定义content。例如

在模板中:

<meta name="title" content="#{titleParam}" />

在使用模板的页面中:

<ui:param name="titleParam" value="customValueForThisPage" />

【讨论】:

  • 您好 Bozho,感谢您的回复。不幸的是,
  • 在定义标签之外使用它。它在我当前的应用程序中运行良好。
  • 是的,在定义标签之外工作。但我需要定义标签内的信息来实现 ui:parameter value :s
【解决方案2】:

我不认为 facelets 是这样工作的。它编译并读取模板。

所以我认为你可以只定义你想要多少个定义而不关心嵌套。

即:

//In your template.xhtml
<ui:insert name="outer">
    BLA BLA BLA
    <ui:insert name="inner"/>
    BLA BLA BLA
</ui:insert>

当你想简单地使用这个模板时:

 <ui:define name="outer">
    Here you can overwrite outer (This will probably overwrite inner, not sure, you need to test it)
 </ui:define>

 <ui:define name="inner">
    Or you can ONLY overwrite inner here if you want
 </ui:define>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    • 2021-12-17
    • 2013-12-22
    相关资源
    最近更新 更多