对象不支持此属性或方法,其中primefaces omnifaces超时组合 [英] Object doesn't support this property or method with primefaces omnifaces timeout combination

查看:148
本文介绍了对象不支持此属性或方法,其中primefaces omnifaces超时组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Setup: JSF, PrimeFaces 3.2, Omnifaces 1.1, JBoss AS 7.1.1, Final, Mojarra 2.1.7

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

I have a simple page (listed below) and I have set up omnifaces to deal with ViewExpiredExceptions for ajax calls. When the listed below page expires and I click on a primefaces button (ajax) on IE8, the expired error page shows up but with the following javascript error:

消息:对象不支持此属性或方法,行:1个字符:5500代码:0 URI:blah blah / mywebapp / javax.faces.resource / primefaces.js.xhtml?ln = primefaces& v = 3.2

Message: Object doesn't support this property or method, Line: 1 Char: 5500 Code: 0 URI: blah blah/mywebapp/javax.faces.resource/primefaces.js.xhtml?ln=primefaces&v=3.2

它似乎不会在其他浏览器上产生错误。

It doesn't seem to produce an error on other browsers.

我的页面(home.xhtml):

My page (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

The timeout error page: 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

The template 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还有其他位:

Web.xml has among other bits:

    <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错误。

When I click on the second button after expiration, then the expired page shows without javascript errors.

任何想法?

推荐答案

这是PrimeFaces的已知问题<$在基于IE的浏览器中c $ c> update =@ all。整个视图已被 document.write()取代,但基于IE的浏览器无法正确加载/初始化任何< script> 资源。另请参阅此 PrimeFaces论坛主题。这将针对 PrimeFaces 3.4.2版进行解决。

This is a known issue of PrimeFaces update="@all" in IE based browsers. The entire view is been replaced by document.write(), however IE based browsers doesn't properly load/initialize any <script> resources. See also this PrimeFaces forum topic. This will be addressed for PrimeFaces version 3.4.2.

在此之前,您可以使用以下JavaScript解决方法

Until then, you can workaround it using the following 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

which needs to be loaded after PrimeFaces own JS resources; this can be done by referencing it in <h:body> with target="head".

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

请注意,这假设当前视图使用的是PrimeFaces组件,而这些组件又会强制自动包含 primefaces.js jquery.js 脚本。否则你必须手动声明它们。

Note that this assumes that the current view is using PrimeFaces components which should in turn force auto-inclusion of primefaces.js and jquery.js scripts. Otherwise you've to manually declare them.

这篇关于对象不支持此属性或方法,其中primefaces omnifaces超时组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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