Primefaces咆哮不适用于所有页面 [英] Primefaces growl is not working in all the pages

查看:105
本文介绍了Primefaces咆哮不适用于所有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有一个通用模板,即xhtml file而包含growl

My web has a common template i.e. xhtml file while contains growl

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

此模板在所有页面中都有使用.我注意到growl适用于页面index.xhtml,但不适用于其余页面.以下是faces-config.xml文件的片段-

This template is used further in all pages. I noticed that growl is working for page index.xhtml but not working in rest of the pages. Below is the snippet of faces-config.xml file-

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

但是,每当我通过链接http://localhost:8080/portal/home.xhtml访问页面home.xhtml时,growl就会开始工作.在所有页面中,我都使用update=":message"更新growl.罪魁祸首是什么?

But whenever I am accessing the page home.xhtml via link http://localhost:8080/portal/home.xhtml, growl starts working. In all the pages I am using update=":message" to update growl. Which is the culprit?

下面是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>

下面是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>

下一页home.xhtml也正在使用base.xhtml,其使用方式与index.xhtml正在使用...的下面是它的摘录-

The next page home.xhtml is also using base.xhtml in the same way as index.xhtml is using it... Below is the snippet of it-

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

推荐答案

如果带有UICommand按钮的的父项是 预先由ajax请求渲染/更新,然后执行第一个操作 将永远失败.第二步和后续操作将起作用.这是 由视图状态处理中的错误引起,报告为JSF规范 问题790,并在JSF 2.2中修复.对于JSF 2.0和2.1,您需要 在的呈现中明确指定的ID <f:ajax>

If a parent of the with the UICommand button is been rendered/updated by an ajax request beforehand, then the first action will always fail. The second and subsequent actions will work. This is caused by a bug in view state handling which is reported as JSF spec issue 790 and fixed in JSF 2.2. For JSF 2.0 and 2.1 you need to explicitly specify the ID of the in the render of the <f:ajax>

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

Says BalusC here. So in your case you are doing navigation to another page and stucks into that view state bug, ajax=false indicates submit the button without AJAX that's why it works.

BalusC还建议在此处的脚本中使用此漏洞.

Also BalusC suggests to use a script which fixes this bug here.

这篇关于Primefaces咆哮不适用于所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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