javax.faces.application.ViewExpiredException和错误页面不工作



我设置我的web应用程序如下:

 <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/WEB-INF/include/viewExpired.html</location>
</error-page>

以便在抛出viewExpiredException时显示上述错误页面。

但是,当我重新启动服务器并在"左打开"页面上提交ajax请求时,在控制台中抛出异常,并且不显示我的错误页面。

下面是来自控制台的堆栈跟踪:

javax.faces.application.ViewExpiredException: viewId:/contact.jsf - La vue /contact.jsf na pas pu être restaurée.
        at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:200)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
        at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.jeanbaptistemartin.util.DisableUrlSessionFilter.doFilter(DisableUrlSessionFilter.java:70)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:662)
有谁有什么线索吗?

提前感谢,j .

那么您想在标准JSF 2.0实现上处理Ajax错误?标准JSF实现没有为此提供现成的组件。例如,在PrimeFaces中,您可以为此使用<p:ajaxStatus>组件。然而,JSF 2.0规范在13.3.6.2章中概述了以下内容:

13.3.6.2处理所有Ajax请求的错误

JavaScript API提供了jsf.ajax.addOnError函数,可以用来注册一个JavaScript函数,当任何Ajax请求/响应发生错误时,该函数将被通知。请参阅第14.4节"注册回调函数"了解更多细节。jsf.ajax.addOnError函数接受一个JavaScript函数参数,该参数将是在任何Ajax请求/响应周期中发生错误时通知。[P1-start-event]实现必须保证被注册的JavaScript函数必须按照表14-5中列出的错误来调用"错误"

你可以在这里找到一个Mojarra开发人员的博客,其中包含了如何显示ajax状态的基本示例。以下是相关内容的摘录:

<h3> Status:</h3>
<textarea id="statusArea" cols="40" rows="10" readonly="readonly" />

一个简单的文本区,甚至没有钩到后端服务器数据模型。

然后在我们的javascript(用于演示)中,在一个单独加载的文件中也可以很容易地在页)我们:

var statusUpdate = function statusUpdate(data) {
    var statusArea = document.getElementById("statusArea");
    var text = statusArea.value;
    text = text + "Name: "+data.source.id;
    if (data.type === "event") {
        text = text +" Event: "+data.name+"n";
    } else {  // otherwise, it's an error
        text = text + " Error: "+data.name+"n";
    }
    statusArea.value = text;
};
// Setup the statusUpdate function to hear all events on the page
jsf.ajax.addOnEvent(statusUpdate);
jsf.ajax.addOnError(statusUpdate);

你也可以使用JS重定向到错误页面。

window.location = '/errors/500.xhtml';

相关内容

  • 没有找到相关文章

最新更新