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

/ UI Layout Initialization Error The center-pane element does not exist. The center-pane is a required element

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

我的问题与 primefaces 有关,我尝试了很多解决方案,但对我没有任何作用。

我正在使用...

下面的代码是我的 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>

当我 运行 我的应用程序请求成功到达控制器并且 return。但是浏览器发出警报

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

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

提前致谢。

你的组件和标签结构都是错误的。它应该是这样的。

<!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>
  • 主要错误:布局和内容属于 body,而不是头部。
  • 标题和元标记必须在标题中。
  • 模板无法使用 f:metadata。客户端视图可以。参见 f:metadata doc
  • 在 f:view 中定义内容类型和编码。
  • f:view 中没有 id 属性。

顺便说一下,我不推荐使用 ui:debug。它评估它能看到的所有属性,有时会引发不受欢迎的 side-effects.