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

Jsf 2 /UI布局初始化错误中心窗格元素不存在。中间窗格是必需的元素,jsf-2,primefaces,Jsf 2,Primefaces,我是stackoverflow的新手,这也是我在这个论坛上的第一个问题,所以如果我在这里发帖时做错了什么,请让我知道 我的问题与素面有关,我尝试了很多解决方案,但都不管用 我正在使用 JSF2.2.4 primefaces 5.2 雄猫8 下面的代码是my template.xhtml 它位于/templates/template.xhtml上 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

我是stackoverflow的新手,这也是我在这个论坛上的第一个问题,所以如果我在这里发帖时做错了什么,请让我知道

我的问题与素面有关,我尝试了很多解决方案,但都不管用

我正在使用

  • JSF2.2.4
  • primefaces 5.2
  • 雄猫8
下面的代码是my 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>

带素数面的页面模板

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

你好,世界!欢迎使用从模板派生的页面

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

/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>

带素数面的页面模板
  • 主要错误:版面和内容属于主体,而不是主体
  • 标题和元标记必须在标题中
  • 模板无法使用f:元数据。客户端视图可以。看
  • 在f:view中定义内容类型和编码
  • f:view中没有
    id
    属性

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

没有冒犯,但我会通过搜索SO或谷歌(除了这个例外)。没有朋友。。我已经试过了,但那对我不起作用。我已经在web.xml中添加了这一部分,但这对我来说不起作用,它现在起作用了!!!非常感谢你。。。不幸的是,我不能给你的答案打分,因为我是新来的。但你的回答对我有用。再次感谢你节省了我的时间。你也很好地解释了我做错了什么。谢谢你所做的一切。我从你那里学到了很多东西。谢谢你的完成。。。我只是不能为那些不发布他们尝试过的和不起作用的内容的人创建这样的答案…@randikaisuru,要接受答案,请单击答案左侧的复选标记,它就在投票箭头的正下方。哦!!对不起,我不知道。我想现在一切都好了。