/ UI布局初始化错误中心窗格元素不存在。中心窗格是必填元素

时间:2015-05-28 18:35:19

标签: jsf-2 primefaces

我是stackoverflow的新手,这也是我对这个论坛的第一个问题,所以如果我在这里发帖时做错了,请告诉我。

我的问题与primefaces有关,我尝试了很多解决方案,但对我来说没什么用。

我正在使用......

  • jsf 2.2.4
  • primefaces 5.2
  • tomcat 8

下面的代码是我的template.xhtml 它位于/templates/template.xhtml

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">

<f:view contentType="text/html" id="fview">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page template with PrimeFaces</title>
<ui:debug />
<f:metadata>
    <ui:insert name="metadata" />
</f:metadata>

<h:head>
    <p:layout fullPage="true" resizeTitle="resize"
        style="background-color:#FFFFFF;">

        <p:layoutUnit position="north" size="68" id="north">
            <ui:include src="header.xhtml" />
        </p:layoutUnit>

        <p:layoutUnit position="west" id="west" resizable="false" size="225">
            <ui:include src="menu.xhtml" />
        </p:layoutUnit>

        <p:layoutUnit position="center" id="centerLayout">
            <h:form id="mainForm">
                <p:messages autoUpdate="true" id="msgs" showDetail="true"
                    showSummary="true" />
                <ui:insert name="content" />
            </h:form>
        </p:layoutUnit>

        <p:layoutUnit position="east" size="0"
            style="width:0px; display:none;" id="east">
        </p:layoutUnit>

        <p:layoutUnit position="south" resizable="true" id="south">
            <ui:include src="footer.xhtml" />
        </p:layoutUnit>

    </p:layout>

</h:head>

以下代码是我的home.xhtml 它位于pages / home.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
template="../templates/template.xhtml">
<ui:define name="metadata">
</ui:define>
<ui:define name="content">
    Hello world! Welcome to a page derived from a template 
</ui:define>

当我成功运行我的应用程序请求时,转到控制器并返回。但是浏览器会提出警报

&GT; / UI布局初始化错误 中心窗格元素不存在。 中心窗格是必需元素。

如果有人知道我的问题的正确答案,请帮助我。

提前致谢。

1 个答案:

答案 0 :(得分:3)

您的组件和标签结构都是错误的。这是它的外观。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">

<f:view encoding="UTF-8" contentType="text/html">

    <ui:insert name="metadata" />

    <h:head>
        <title>Page template with PrimeFaces</title>
    </h:head>

    <h:body>
        <ui:debug />
        <p:layout fullPage="true" resizeTitle="resize" style="background-color:#FFFFFF;">

            <p:layoutUnit position="north" size="68" id="north">
                <ui:include src="header.xhtml" />
            </p:layoutUnit>

            <p:layoutUnit position="west" id="west" resizable="false" size="225">
                <ui:include src="menu.xhtml" />
            </p:layoutUnit>

            <p:layoutUnit position="center" id="centerLayout">
                <h:form id="mainForm">
                    <p:messages autoUpdate="true" id="msgs" showDetail="true" showSummary="true" />
                    <ui:insert name="content" />
                </h:form>
            </p:layoutUnit>

            <p:layoutUnit position="east" size="0" style="width:0px; display:none;" id="east">
            </p:layoutUnit>

            <p:layoutUnit position="south" resizable="true" id="south">
                <ui:include src="footer.xhtml" />
            </p:layoutUnit>

        </p:layout>
    </h:body>

</f:view>
</html>
  • 主要错误:布局和内容属于正文,而不是头部。
  • 标题和元标记必须在头部。
  • 模板无法使用f:元数据。客户端视图可以。见f:metadata doc
  • 在f:view中定义内容类型和编码。
  • f:view。
  • 中没有id属性

顺便说一下,我不推荐使用ui:debug。它评估它可以看到的所有属性,有时会引起不良副作用。