【问题标题】:JSF/PrimeFaces - Template with <p:layout>JSF/PrimeFaces - 带有 <p:layout> 的模板
【发布时间】:2012-05-21 16:48:31
【问题描述】:

我需要创建一个类似this 的布局,但所有容器都位于单独的文件中,例如:

top.xhtml

<p:layout fullPage="true">
        <p:layoutUnit position="north" header="#{support.applicationTitle}">
            <h:form>
                <p:menubar>
                    <p:menuitem value="Quit" icon="ui-icon-close" action="#{userController.logOut()}" />
                </p:menubar>
            </h:form>
        </p:layoutUnit>

没有&lt;/p:layout&gt; 因为它会靠近我的footer.xhtml,例如:

<p:layoutUnit position="south" header="© 2012 - 2012 PORTAL DE IDEIAS">
</p:layoutUnit></p:layout>

我已经尝试了这两个文件,但我收到一个错误,告诉我需要关闭 layout 标签,这是正确的,但我该如何解决我的问题?这是模板的最佳方法吗?另一个问题是 layout 标签需要一个中心 layoutUnit

【问题讨论】:

    标签: templates jsf layout primefaces facelets


    【解决方案1】:

    这确实不是正确的做法。您的模板必须是格式良好的 XML。如果您只想指定中心单元,我建议创建一个主模板文件。

    以展示网站上的示例为例,应该如下所示:

    /WEB-INF/templates/layout.xhtml

    <!DOCTYPE html>
    <html lang="en"
         xmlns="http://www.w3.org/1999/xhtml"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:p="http://primefaces.org/ui"
    >
        <h:head>
            <title>Title</title>
        </h:head>
        <h:body>
            <p:layout fullPage="true">
                <p:layoutUnit position="north" size="100" header="Top" resizable="true" closable="true" collapsible="true">
                    <h:outputText value="Top unit content." />
                </p:layoutUnit>
    
                <p:layoutUnit position="south" size="100" header="Bottom" resizable="true" closable="true" collapsible="true">
                    <h:outputText value="South unit content." />
                </p:layoutUnit>
    
                <p:layoutUnit position="west" size="200" header="Left" resizable="true" closable="true" collapsible="true">
                    <h:form>
                        <ui:include src="../templates/themeMenu.xhtml" />
                    </h:form>
                </p:layoutUnit>
    
                <p:layoutUnit position="east" size="200" header="Right" resizable="true" closable="true" collapsible="true" effect="drop">
                    <h:outputText value="Right unit content." />
                </p:layoutUnit>
    
                <p:layoutUnit position="center">
                    <ui:insert name="content">Put default content here, if any.</ui:insert>
                </p:layoutUnit>
            </p:layout>
        </h:body>
    </html>
    

    注意中心单元中的&lt;ui:insert&gt;

    模板客户端可以如下所示:

    /page.xhtml

    <ui:composition template="/WEB-INF/templates/layout.xhtml"
         xmlns="http://www.w3.org/1999/xhtml"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:p="http://primefaces.org/ui"
    >
         <ui:define name="content">
             <p>Here goes your view-specific content.</p>
         </ui:define>
    </ui:composition>
    

    您通过http://example.com/contextname/page.xhtml打开。

    另见:

    如果您正在寻找高级 Facelets 模板的实时开源示例,您可能会发现 OmniFaces showcase app 很有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      • 2018-04-29
      • 2013-10-21
      • 1970-01-01
      相关资源
      最近更新 更多