如何在调用OmniFaces“FullAjaxExceptionHandler”后阻止PrimeFaces轮询连续轮询

时间:2013-06-26 11:56:15

标签: jsf primefaces polling omnifaces

我正在使用PrimeFaces 3.5和OmniFaces 1.5。在我的主页上,我有一个民意调查组件来刷新一些内容。另外,我正在使用FullAjaxExceptionHandler在ajax请求期间出现异常时显示错误页面。

index.xhtml

<h:form id="formBsvtt">
  <p:messages autoUpdate="true" showDetail="false" />
  <p:outputPanel id="panelOut" layout="block">
    ...
    ... content to refresh
    ...
  </p:outputPanel>
  <p:panelGrid id="panelIn" layout="block">
    ...
    ... various interaction with user and database access
    ...
    <ui:include src="page1.xhtml" />
    <ui:include src="page2.xhtml" />
    <ui:include src="page3.xhtml" />
    ...
  </p:panelGrid>
  <p:poll widgetVar="poll1" autoStart="true" global="false" interval="15" 
    partialSubmit="true" process="@this" update="panelOut"
    listener="#{myBean.myListener}">
  </p:poll>
</h:form>

web.xml

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/errorViewExpired.xhtml</location>
</error-page>
<error-page>
    <exception-type>java.sql.SQLException</exception-type>
    <location>/errorSQL.xhtml</location>
</error-page>
<error-page>
    <exception-type>java.lang.RuntimeException</exception-type>
    <location>/errorRuntime.xhtml</location>
</error-page>

我的问题是:如果出现异常,将显示指定的错误页面,但不会停止轮询,然后每隔15秒显示一次ViewExpired错误页面。我试图用

来阻止它
<h:outputScript>poll1.stop();</h:outputScript>

在错误页面上,但这不起作用。

如果出现异常,如何停止投票?


更新我不使用模板。这是我的错误页面:

<?xml version="1.0" encoding="UTF-8" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:of="http://omnifaces.org/functions">

    <h:head>
    </h:head>

    <h:body>

        In der Anwendung trat ein Laufzeitfehler auf!
        <p><a href="#{requestScope['javax.servlet.error.request_uri']}">Anwendung neu starten ...</a></p>
        <ul>
            <li>Date/time: #{of:formatDate(now, 'yyyy-MM-dd HH:mm:ss')}</li>
            <li>User agent: #{header['user-agent']}</li>
            <li>User IP: #{empty header['x-forwarded-for'] ? request.remoteAddr : fn:split(header['x-forwarded-for'], ',')[0]}</li>
            <li>Request URI: <a href="#{requestScope['javax.servlet.error.request_uri']}">#{requestScope['javax.servlet.error.request_uri']}</a></li>
            <li>Ajax request: #{facesContext.partialViewContext.ajaxRequest ? 'Yes' : 'No'}</li>
            <li>Status code: #{requestScope['javax.servlet.error.status_code']}</li>
            <li>Exception type: #{requestScope['javax.servlet.error.exception_type']}</li>
            <li>Exception message: #{requestScope['javax.servlet.error.message']}</li>
            <li>Stack trace: <pre><code>#{of:printStackTrace(requestScope['javax.servlet.error.exception'])}</code></pre></li>
        </ul>
        <h:outputScript>poll1.stop();</h:outputScript>
        <h:outputScript>poll2.stop();</h:outputScript>
        <h:outputScript rendered="#{facesContext.partialViewContext.ajaxRequest}">scrollTo(0, 0);</h:outputScript>

    </h:body>

</html>

0 个答案:

没有答案