Primefaces咆哮不适用于所有页面

Rav*_*shi 4 jsf primefaces

我的网站有一个共同的模板,即xhtml file同时包含growl

<p:growl id="message" showDetail="true" life="3000" />
Run Code Online (Sandbox Code Playgroud)

该模板将在所有页面中进一步使用。我注意到这growl适用于页面,index.xhtml但不适用于其余页面。以下是faces-config.xml文件的摘要-

<navigation-rule>
    <display-name>index.xhtml</display-name>
    <from-view-id>/index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>NORMAL_USER</from-outcome>
        <to-view-id>/home.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>
Run Code Online (Sandbox Code Playgroud)

但是,每当我home.xhtml通过link 访问页面时http://localhost:8080/portal/home.xhtml,便 growl开始工作。在我update=":message"用来更新的所有页面中growl。罪魁祸首是哪个?

下边是 index.xhtml

<ui:composition template="/template/common/base.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

    <ui:define name="center">

        <h:form>
            <div align="center" style="margin-top: 10%; margin-bottom: 10%;">
                <p:panelGrid columns="2">
                    <f:facet name="header">  
                     #{msg.HEADER}
                    </f:facet>

                    <h:outputLabel for="username" value="#{msg.USERNAME}" />
                    <p:inputText id="username" value="#{client.user.username}"
                        required="true" requiredMessage="#{msg.USERNAME_REQUIRED_MSG}" />

                    <h:outputLabel for="password" value="#{msg.PASSWORD} " />
                    <p:password id="password" value="#{client.user.password}"
                        required="true" requiredMessage="#{msg.PASSWORD_REQUIRED_MSG}" />

                    <f:facet name="footer">
                        <div align="right">
                            <p:commandButton value="#{msg.LOGIN_BUTTON}" icon="ui-icon-check"
                                update=":message" action="#{client.login}" />
                        </div>
                    </f:facet>
                </p:panelGrid>
            </div>
        </h:form>

    </ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

下边是 base.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:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>My Web Portal</title>
    <h:outputStylesheet library="css" name="default.css" />
</h:head>

<h:body>

    <p:growl id="message" showDetail="true" life="3000" />

    <h:link outcome="index" style="text-decoration: none;">
        <div id="header" style="margin: 2px; width: 100%; text-align: center;">
            <p:panel>
                <h:outputText value="My Web Portal"
                    style="font-size: 20px; " />
            </p:panel>
        </div>
    </h:link>

    <div id="middle" style="margin: auto; width: 80%;">
        <ui:insert name="center"></ui:insert>
    </div>

    <div id="footer"
        style="clear: both; text-align: center; margin: 2px; width: 100%;">
        <p:panel header="2013 All rights reserved. Designed by Ravi Joshi">
            <h:link value="Home" outcome="index" />
            <p:spacer width="10px;" />
            <h:link value="About Us" outcome="index" />
            <p:spacer width="10px;" />
        </p:panel>
    </div>

</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

下一页的home.xhtml使用base.xhtml方式index.xhtml也与之相同。下面是该摘要的片段-

<ui:composition template="/template/common/base.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

    <ui:define name="center">

    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->
    <!--  -->


    </ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

Öme*_*alı 5

如果预先通过ajax请求渲染/更新了带有UICommand按钮的父元素,则第一个操作将始终失败。第二步和后续操作将起作用。这是由视图状态处理中的错误引起的,该错误报告为JSF规范问题790,并已在JSF 2.2中修复。对于JSF 2.0和2.1,您需要在渲染器中显式指定ID <f:ajax>

BalusC 在这里说。因此,在您的情况下,您正在导航到另一个页面并陷入该视图状态错误,这ajax=false表示提交没有AJAX的按钮,这就是它起作用的原因。

BalusC还建议在此处使用脚本来修复此错误