2012-10-11 96 views
2

我想使用omnifaces的FullAjaxExceptionHandler,但我得到StringIndexOutOfBoundsExceptionorg.omnifaces.util.Faces.normalizeViewId(Faces.java:312) [omnifaces-1.1.jar:1.1]使用FullAjaxExceptionHandler時StringIndexOutOfBoundsException

我的web.xml文件中有如下錯誤設置:

<error-page> 
    <exception-type>java.lang.Throwable</exception-type> 
    <location>/ErroServlet</location> 
</error-page> 

哪裏ErroServlet是我的servlet,做重定向到正確的錯誤頁面,根據請求的URL(我有2個不同的錯誤頁) 。

我試圖使用FullAjaxExceptionHandler,以便在ajax請求期間拋出的異常也被處理。

我ErroServlet檢查它是否使用Ajax請求:

private boolean isXMLHttpRequest(HttpServletRequest request) { 
    return "partial/ajax".equals(request.getHeader("Faces-Request")); 
} 

如果屬實,它重定向使用:

resp.setContentType("text/xml"); 
resp.getWriter().append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") 
    .printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", url); 

正如我所說的,我得到一個StringIndexOutOfBoundsException該servlet完成後。而且,頁面確實不會在視覺上重定向

完整堆棧跟蹤:

11:47:26,435 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/pso]] (http--0.0.0.0-8080-1) An exception occurred during JSF ajax request. Showing error page location '/ErroServlet'.: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
    at java.util.ArrayList.rangeCheck(Unknown Source) [rt.jar:1.7.0_07] 
    at java.util.ArrayList.get(Unknown Source) [rt.jar:1.7.0_07] 
    at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1560) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at com.sun.faces.application.view.FaceletPartialStateManagementStrategy$2.visit(FaceletPartialStateManagementStrategy.java:380) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:367) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:138) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:518) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:142) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) [primefaces-3.4.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [solder-impl-3.1.0.Final.jar:3.1.0.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74) [solder-impl-3.1.0.Final.jar:3.1.0.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at br.ind.seat.pso.filtros.FiltroUrlPattern.doFilter(FiltroUrlPattern.java:50) [classes:] 
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75) [omnifaces-1.1.jar:1.1] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at br.ind.seat.pso.filtros.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:22) [classes:] 
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75) [omnifaces-1.1.jar:1.1] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at br.ind.seat.pso.filtros.FiltroPesquisaLogado.doFilter(FiltroPesquisaLogado.java:45) [classes:] 
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75) [omnifaces-1.1.jar:1.1] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final] 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:] 
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_07] 

11:47:26,437 WARN [org.jboss.solder.exception.control.log] (http--0.0.0.0-8080-1) No handlers found for exception java.lang.StringIndexOutOfBoundsException: String index out of range: -1 
11:47:26,438 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/pso].[Faces Servlet]] (http--0.0.0.0-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 
    at java.lang.String.substring(Unknown Source) [rt.jar:1.7.0_07] 
    at org.omnifaces.util.Faces.normalizeViewId(Faces.java:312) [omnifaces-1.1.jar:1.1] 
    at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handle(FullAjaxExceptionHandler.java:179) [omnifaces-1.1.jar:1.1] 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [javax.faces-2.1.9.jar:2.1.9-SNAPSHOT] 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) [primefaces-3.4.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [solder-impl-3.1.0.Final.jar:3.1.0.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74) [solder-impl-3.1.0.Final.jar:3.1.0.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at br.ind.seat.pso.filtros.FiltroUrlPattern.doFilter(FiltroUrlPattern.java:50) [classes:] 
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75) [omnifaces-1.1.jar:1.1] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at br.ind.seat.pso.filtros.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:22) [classes:] 
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75) [omnifaces-1.1.jar:1.1] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at br.ind.seat.pso.filtros.FiltroPesquisaLogado.doFilter(FiltroPesquisaLogado.java:45) [classes:] 
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75) [omnifaces-1.1.jar:1.1] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final] 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:] 
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_07] 

回答

2

the FullAjaxExceptionHandeler javadoc

這異常處理程序將解析web.xml和網絡fragment.xml之文件,找到HTTP錯誤的錯誤頁面位置代碼500和所有聲明的特定異常類型。 這些位置需要指向Facelets文件。

一個普通的servlet位置不被支持,因爲它是不可能創建一個圍繞它的UIViewRoot,更不用說JSF ViewHandler來呈現它。

您最好創建一個完整的Facelets文件,它包含/呈現動態請求特定的錯誤頁面內容。

StringIndexOutOfBoundsException是一個獨立的錯誤,在OmniFaces 1.2的最新快照中已經修復。

+0

謝謝。我想我可以指向一個servlet,然後指向一個Facelet頁面,但我理解你的解釋。我只需將''更改爲'',並驗證postContruct中的請求URI以返回正確的佈局。現在更簡單了。非常感謝你。 :) – RinaldoPJr

+0

不客氣。 – BalusC

相關問題