Primefaces UI布局初始化错误6.2

Primefaces UI布局初始化错误6.2,primefaces,jsf-2.2,Primefaces,Jsf 2.2,以下代码适用于PrimeFaces 6.0和6.1,但在6.2中,当我单击“验证”按钮时,我会看到带有消息的对话框: / UI Layout Initialization Error The center-pane element does not exist. The center-pane is a required element. 我使用:jsf2.2,PrimeFaces 6.2,Tomcat 8.5.23 代码是否有问题或问题在PrimeFaces 6.2中 Compan

以下代码适用于PrimeFaces 6.06.1,但在6.2中,当我单击“验证”按钮时,我会看到带有消息的对话框:

/ UI Layout Initialization Error  
The center-pane element does not exist.  
The center-pane is a required element.
我使用:
jsf2.2
PrimeFaces 6.2
Tomcat 8.5.23

代码是否有问题或问题在
PrimeFaces 6.2中

Company.java

MessagesHelper.java

validation.xhtml


footer.xhtml


header.xhtml


menu.xhtml


template.xhtml


项目名称
web.xml


项目
javax.faces.STATE_保存方法
服务器
javax.faces.PROJECT_阶段
发展
Facesservlet
javax.faces.webapp.FacesServlet
1.
真的
假的
Facesservlet
*.xhtml

PrimeFaces 6.2中存在导致此问题的错误。
该错误已在PrimeFaces 6.2.1中报告并解决

更多信息可在此处找到:

正如melloware在上面的链接中提到的,在web.xml中添加以下代码可以解决这个问题

<context-param>
    <param-name>primefaces.MOVE_SCRIPTS_TO_BOTTOM</param-name>
    <param-value>true</param-value>
</context-param>

primefaces.MOVE_SCRIPTS_至_底部
真的

添加带有自动更新的p:messages。您很可能会看到错误。但是错误也可能出现在服务器日志中…并尝试将代码简化为…我添加了一个带有自动更新的p:messages,但仍然收到相同的错误。我检查了服务器日志(catalina.out),它是空的
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

public class MessagesHelper {
    public static void addMessage(String summary) {
        addMessage(summary, null);
    }

    public static void addMessageError(String summary) {
        addMessageError(summary, null);
    }

    public static void addMessage(String summary, String detail) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public static void addMessageError(String summary, String detail) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}
<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" 
    template="../templates/template.xhtml">    
    <ui:define name="content">
        <h:form id="frmValidate">
            <p:growl id="msgs" showDetail="true" /> 
            <div class="ui-fluid">  
                <div class="ui-grid ui-grid-responsive">
                    <div class="ui-grid-row">
                        <p:outputLabel for="regNumber" value="Registration Number: "></p:outputLabel>                               
                        <p:inputText id="regNumber" styleClass="inputClass" value="#{company.regNumber}" />
                        <p:commandButton value="Validate" id="btnValidate" ajax="false" action="#{company.validateRegNumber()}" />  
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
    <center>
        <h:outputText style="font-size:13" value="Company Name 2018" />
    </center>
</ui:composition>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
    <center>
        <h:form id="formWelcome">
            <p:toolbar id="toolbarWelcome">
                <p:toolbarGroup align="left" styleClass="my-toolbar-group-left">
                    <h:outputText value="Project Name" />
                </p:toolbarGroup>
                <p:toolbarGroup align="right">
                    <p:outputLabel for="uname" value="Username:" />
                    <p:outputLabel id="uname" value=" myUserName" />
                </p:toolbarGroup>
            </p:toolbar>
        </h:form>
    </center>
</ui:composition>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
    <h:form>
        <p:panelMenu style="width:212px">
            <p:submenu label="Main Menu">
                <p:menuitem value="Submenu 1"/>
                <p:menuitem value="Submenu 2"/>
            </p:submenu>
        </p:panelMenu>
    </h:form>
</ui:composition>
<!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" encoding="UTF-8">
  <h:head>
   <f:facet name="first">
       <link rel="shortcut icon" type="image/x-icon" href="#{resource['images/favicon.ico']}" />  
       <meta http-equiv="X-UA-Compatible" content="IE=edge" />
       <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
       <title>Project Name</title>
   </f:facet> 

    <f:facet name="middle">
        <h:outputStylesheet name="css/style.css" />
   </f:facet>
 </h:head>
   <h:body>
    <p:layout fullPage="true" resizeTitle="resize">
        <p:layoutUnit  position="north"  id="north" size="60" resizable="false">
            <ui:include src="header.xhtml" />
        </p:layoutUnit>

        <p:layoutUnit id="west" position="west" size="220" resizable="false" gutter="2" header="Actions" effect="slide" collapsible="true" >
            <ui:include src="menu.xhtml" />
        </p:layoutUnit>

         <p:layoutUnit id="center" styleClass="layoutUnitCenter" position="center" resizable="false">               
                <!-- For PrimeFaces <= 6.1 -->
                <!-- 
                    <p:messages id="msgs" showSummary="true" autoUpdate="true" />
                    <ui:insert name="content" />
                 -->

                <!-- For PrimeFaces == 6.2 -->
                <p:fragment>
                    <p:messages id="msgs" showSummary="true">
                        <p:autoUpdate />
                    </p:messages>
                </p:fragment>
                <ui:insert name="content" />
        </p:layoutUnit>

        <p:layoutUnit position="south" resizable="false" id="south" closable="false" collapsible="false">
            <ui:include src="footer.xhtml" />
        </p:layoutUnit>
    </p:layout>
    </h:body>
</f:view>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <display-name>Project</display-name>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>    
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <enabled>true</enabled>
        <async-supported>false</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>
<context-param>
    <param-name>primefaces.MOVE_SCRIPTS_TO_BOTTOM</param-name>
    <param-value>true</param-value>
</context-param>