【问题标题】:How to use <f:loadBundle> tag inside <ui:composition> tag如何在 <ui:composition> 标签内使用 <f:loadBundle> 标签
【发布时间】:2011-10-18 06:36:52
【问题描述】:

我想在我的视图中使用&lt;f:loadBundle&gt; 标签。我知道我可以在faces-config.xml 中声明它,但出于某种原因,我想在我的视图中使用它。我以这种方式使用标签,但它不起作用。我在&lt;ui:composition&gt; 标签内使用它。

<h:head>
    <title>Email Content</title>
</h:head>
<h:body>
    <ui:composition template="./WEB-INF/templates/layout.xhtml">
        <ui:define name="content">
            <f:loadBundle basename="presentationBeans.homepage.messages" var="msgs"/>
            <h:form id="emailContent_Review" >
                <p:growl id="growl" showDetail="true" />
                <p:panel id="panel"  
                    header="#{msgs.ECR_panelHeader}" 
                    style="border-color: #000000;width: 960px;position: absolute;left: 150px;height: 370px" >
                    <p:dataTable value="#{emailContent_Review.emailContent}"
                        var="emailContent"
                        selection="#{emailContent_Review.selectedEmailContent}"
                        emptyMessage="#{msgs.ECR_tableEmptyMessage}" 
                        widgetVar="portalsTable"
                        rows="8" height="350" paginator="true">
                        <f:facet name="header" >
                        </f:facet>
                    </p:dataTable>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>
</h:body>

我做错了什么?我也读到了

要使用模板,您可以使用带有“模板”属性的“ui:composition”标签。 Facelets 删除了标签之外的所有标签——即 doctype 声明、html、head、title 和 body 标签。这是必要的,因为 &lt;ui:composition&gt; 被替换为包含其自己的一组 html、head、title 和 body 标记的模板。

如果我想在 head 部分使用我的属性文件,那么我该如何使用它?因为 head 部分在 &lt;ui:composition&gt; 标签之外。我的意思是说,如果我想这样做

<h:head>
    <title>#{msgs.indexWindowTitle}</title>
</h:head>

那么我如何在&lt;ui:composition&gt;之外使用我的属性文件?

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    这确实行不通。更改您的主模板layout.xhtml 以将标题替换为模板插入占位符:

    <h:head>
        <title><ui:insert name="title">Default title</ui:insert></title>
    </h:head>
    

    然后改变你的模板客户端来定义它:

    <ui:composition template="./WEB-INF/templates/layout.xhtml">
        <ui:define name="title">
            <f:loadBundle basename="presentationBeans.homepage.messages" var="msgs"/>
            #{msgs.indexWindowTitle}
        </ui:define>
        <ui:define name="content">
            ...
        </ui:define>
    </ui:composition>
    

    请注意,您无需为&lt;ui:define name="content"&gt; 重复&lt;f:loadBundle&gt;。

    【讨论】:

    • 您好,抱歉,回复晚了。非常感谢 :) ;)
    • @BalusC 通常你想要一个f:loadBundle 是你的主模板,但现在你建议把它放到每个视图中?
    【解决方案2】:

    我已经找到了一种在 Mojarra 2.1.x 上对我很有效的方法,也许可以试一试。调整@BalusC 的例子:

    <ui:composition>
        <f:loadBundle basename="presentationBeans.homepage.messages" var="msgs"/>
    
        <ui:decorate template="./WEB-INF/templates/layout.xhtml">
            <ui:define name="title">
                #{msgs.indexWindowTitle}
            </ui:define>
            <ui:define name="content">
                ...
            </ui:define>
        </ui:decorate>
    </ui:composition>
    

    我将模板化的 ui:decorate 嵌套在裸 ui:composition 标记中的方法对我来说效果很好,因为我经常想要声明一个 f:loadBundle 标记,该标记由所有嵌套的 ui:define 共享。不确定当我这样做时我让内核做了哪些额外的阴谋,或者我是否正在利用规范的不完整实现来获得我想要的东西。 YMMV

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 2023-03-24
      • 2020-02-08
      • 2019-01-15
      • 1970-01-01
      • 2022-12-17
      相关资源
      最近更新 更多