如何在<ui:composition>标记内使用<f:loadBundle>标记

Bas*_*sit 4 jsf-2

我想<f:loadBundle>在视图中使用标签。我知道我可以在内部声明它faces-config.xml,但是出于某种原因,我想在我的视图中使用它。我以这种方式使用标签,但无法正常工作。我在<ui:composition>标签内使用它。

<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>
Run Code Online (Sandbox Code Playgroud)

我做错了什么?我也读过

要使用模板,请使用带有'template'属性的'ui:composition'标签。Facelets会删除标记之外的所有标记-即doctype声明,html,head,title和body标记。这是必需的,因为<ui:composition>替换为包含自己的html,head,title和body标签集的模板。

如果要在头部使用属性文件,该如何使用?因为头部在<ui:composition>标签之外。我的意思是说,如果我想这样做

<h:head>
    <title>#{msgs.indexWindowTitle}</title>
</h:head>
Run Code Online (Sandbox Code Playgroud)

那我如何在外面使用我的属性文件<ui:composition>呢?

Bal*_*usC 5

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

<h:head>
    <title><ui:insert name="title">Default title</ui:insert></title>
</h:head>
Run Code Online (Sandbox Code Playgroud)

然后更改您的模板客户端以定义它:

<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>
Run Code Online (Sandbox Code Playgroud)

请注意,您无需重复<f:loadBundle>for <ui:define name="content">