问题描述
||
我按照以下步骤设置了Web应用程序:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/WEB-INF/include/viewExpired.html</location>
</error-page>
以便在引发viewExpiredException时显示以上错误页面。
但是,当我重新启动服务器并在\“ left-open \”页面上提交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]实施必须确保
必须根据表14-5中概述的错误来调用已注册的JavaScript函数。
“错误”
您可以在这里找到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\';