UI布局初始化错误PrimeFaces 6.2 [英] UI Layout Initialization Error PrimeFaces 6.2

查看:87
本文介绍了UI布局初始化错误PrimeFaces 6.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码在 PrimeFaces 6.0 6.1 上工作正常,但是在我点击 Validate 按钮时使用 6.2 >我看到带有以下消息的对话框:

The following code works fine with PrimeFaces 6.0 and 6.1, but with 6.2 when I click on button Validate I see the dialog with the message:

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

我使用:JSF 2.2PrimeFaces 6.2Tomcat 8.5.23

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

Is there something wrong with the code or the problem is in PrimeFaces 6.2 ?

Company.java

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.company.helper.MessagesHelper;

@ManagedBean(name = "company")
@ViewScoped
public class Company implements Serializable {

    private static final long serialVersionUID = -8386148997526982963L;

    private String regNumber;

    public void validateRegNumber() {
        if(regNumber == null || regNumber.equals("")) {
            MessagesHelper.addMessageError("Invalid Registration Number!");
        } else {
            MessagesHelper.addMessage("Registration Number is Valid!");
        }
    }

    public String getRegNumber() {
        return regNumber;
    }

    public void setRegNumber(String regNumber) {
        this.regNumber = regNumber;
    }
}

MessagesHelper.java

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);
    }
}

validation.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" 
    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>

footer.xhtml

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

header.xhtml

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

menu.xhtml

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

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

web.xml

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

推荐答案

PrimeFaces 6.2中有一个错误会导致此问题.
该错误已报告,并已在PrimeFaces 6.2.1中解决.

There is a bug in PrimeFaces 6.2 that cause this issue.
The bug is reported and is resolved in PrimeFaces 6.2.1

更多信息可以在这里找到: https://github.com/primefaces/primefaces/issues/3457

More info can be found here: https://github.com/primefaces/primefaces/issues/3457

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

As melloware mention in the link above, adding the following code in web.xml solves this issue.

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

这篇关于UI布局初始化错误PrimeFaces 6.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆