2

设置:JSF、PrimeFaces 3.2、Omnifaces 1.1、JBoss AS 7.1.1、Final、Mojarra 2.1.7

我有一个简单的页面(如下所列),并且我已经设置了omnifaces 来处理ajax 调用的ViewExpiredExceptions。当下面列出的页面过期并且我单击 IE8 上的 primefaces 按钮 (ajax) 时,将显示过期的错误页面,但出现以下 javascript 错误:

消息:对象不支持此属性或方法,行:1 字符:5500 代码:0 URI:blah blah/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>

当我在过期后单击第二个按钮时,过期页面显示没有 javascript 错误。

有任何想法吗?

4

1 回答 1

1

update="@all"这是基于 IE 的浏览器中 PrimeFaces 的一个已知问题。整个视图被替换为document.write(),但是基于 IE 的浏览器无法正确加载/初始化任何<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>with中引用它来完成target="head"

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

请注意,这假设当前视图正在使用 PrimeFaces 组件,这些组件应该反过来强制自动包含primefaces.jsjquery.js脚本。否则,您必须手动声明它们。

于 2012-10-10T13:53:47.917 回答