2

セットアップ: JSF、PrimeFaces 3.2、Omnifaces 1.1、JBoss AS 7.1.1、Final、Mojarra 2.1.7

簡単なページ (以下にリスト) があり、ajax 呼び出しの ViewExpiredExceptions を処理するために omnifaces をセットアップしました。以下にリストされているページの有効期限が切れ、IE8 でプライムフェイス ボタン (ajax) をクリックすると、期限切れのエラー ページが表示されますが、次の JavaScript エラーが表示されます。

メッセージ: オブジェクトはこのプロパティまたはメソッドをサポートしていません。行: 1 文字: 5500 コード: 0 URI: 何とか何とか/mywebapp/javax.faces.resource/primefaces.js.xhtml?ln=primefaces&v=3.2

他のブラウザではエラーにはならないようです。

マイページ(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:f="http://java.sun.com/jsf/core"
    template="/WEB-INF/templates/layout.xhtml"> 
    <ui:define name="body">
        <h:form id="form_search">
            <p:commandButton id="idbtn1"
                actionListener="#{bean.doSomething}"
                value="Do something (ajax)!">
            </p:commandButton>
            <p:commandButton id="idbtn2" ajax="false"
                actionListener="#{bean.doSomething}"
                value="Do something!">
            </p:commandButton>

        </h:form>
    </ui:define>
</ui:composition>

タイムアウト エラー ページ: expired.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/WEB-INF/templates/layout.xhtml">
    <ui:define name="body">
    Your session has timed out.
    </ui:define>
</ui:composition>

テンプレート layout.xhtml

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">

<f:view contentType="text/html">
    <h:head>
        <f:facet name="first">
            <meta http-equiv="X-UA-Compatible" content="IE=edge" />
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <meta http-equiv="Cache-Control" content="no-cache, no-store, must-    revalidate" />
            <meta http-equiv="Pragma" content="no-cache" />
            <meta http-equiv="Expires" content="0" />
        </f:facet>
        <base href="${facesContext.externalContext.requestContextPath}" />
    </h:head>
    <h:body>
        <ui:insert name="body"></ui:insert>
    </h:body>
</f:view>
</html>

Web.xml には次の要素があります。

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/WEB-INF/errorpages/expired.xhtml</location>
    </error-page>

    <filter>
        <filter-name>facesExceptionFilter</filter-name>
        <filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>facesExceptionFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>

期限切れの後に 2 番目のボタンをクリックすると、期限切れのページが JavaScript エラーなしで表示されます。

何か案は?

4

1 に答える 1

1

update="@all"これは、 IE ベースのブラウザにおける PrimeFaces の既知の問題です。ビュー全体が に置き換えられましたが、IE ベースのブラウザはリソースdocument.write()を適切にロード/初期化しません。<script>このPrimeFaces フォーラムのトピックも参照してください。これは、PrimeFaces バージョン 3.4.2で対処されます。

それまでは、次の JavaScript を使用して回避できます。

var originalPrimeFacesAjaxResponseFunction = PrimeFaces.ajax.AjaxResponse;
PrimeFaces.ajax.AjaxResponse = function(responseXML) {
   var newViewRoot = $(responseXML.documentElement).find("update[id='javax.faces.ViewRoot']").text();

    if (newViewRoot) {
       $('head').html(newViewRoot.substring(newViewRoot.indexOf("<head>") + 6, newViewRoot.indexOf("</head>")));
       $('body').html(newViewRoot.substring(newViewRoot.indexOf("<body>") + 6, newViewRoot.indexOf("</body>")));
    }
    else {
        originalPrimeFacesAjaxResponseFunction.apply(this, arguments);
    }
};

これは、 PrimeFaces が JS リソースを所有した後にロードする必要があります。<h:body>これは、で参照することで実行できますtarget="head"

<h:body>
    <h:outputScript name="script.js" target="head">
    ...
</h:body>

これは、現在のビューが PrimeFaces コンポーネントを使用していることを前提としているため、スクリプトprimefaces.jsjquery.jsスクリプトの自動インクルードが強制されることに注意してください。それ以外の場合は、手動で宣言する必要があります。

于 2012-10-10T13:53:47.917 に答える