在 Omnifaces 中禁用 RestorableViewHandler
Disable RestorableViewHandler in Omnifaces
我在大型 Web 应用程序中同时使用 OmniFaces 1.10 和 Apache MyFaces 2.2.6。当应用程序在生产中 运行 时,我在 Web 服务器 (Tomcat) 日志中收到以下形式的虚假异常:
java.lang.NullPointerException
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.put(ManagedBeanResolver.java:101)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.putInScope(ManagedBeanResolver.java:367)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:340)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:296)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
at org.apache.myfaces.view.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:431)
at org.apache.myfaces.view.facelets.tag.TagAttributeImpl.getBoolean(TagAttributeImpl.java:143)
at org.apache.myfaces.view.facelets.tag.jstl.core.ChooseWhenHandler.isTestTrue(ChooseWhenHandler.java:68)
at org.apache.myfaces.view.facelets.tag.jstl.core.ChooseHandler.apply(ChooseHandler.java:182)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:55)
at org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate.apply(ComponentTagHandlerDelegate.java:373)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:50)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:195)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:520)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:574)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:552)
at org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:240)
at org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
at org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
at org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:188)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(FaceletViewDeclarationLanguage.java:477)
at org.omnifaces.viewhandler.RestorableViewHandler.restoreView(RestorableViewHandler.java:80)
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
我确信这是一个问题,或者至少是应用程序中的边缘情况(例如,错误地使用了一些 bean 变量的 .xhtml 文件),但我无法在测试用例中重现它,而且以前的版本也从未发生过MyFaces 和 OmniFaces。
异常本身似乎被触发,因为 OmniFaces "RestorableViewHandler" 尝试恢复视图只是为了查看它是否包含应自动恢复的标签。当恢复的视图不包含标签时,它会丢弃(已经)恢复的视图。除了明显的性能问题外,这还会触发此 NullPointerException,所以我不想要这个,因此我正在寻找一种方法来完全禁用 RestorableViewHandler。我知道当我这样做时,我将无法使用标签 "enableRestorableView",但这没关系。
如果不修改 OmniFaces 源代码是不可能禁用它的。根据 issue 92 这已经通过让 <o:enableRestorableView>
在某处使用后设置应用程序范围的属性来解决,这样 RestorableViewHandler
可以决定是否尝试恢复视图。
请注意,我真的更喜欢动态注册 RestorableViewHandler
,但是当应用程序之前已经处理过请求时,不可能动态注册 ViewHandler
。 It would only cause an IllegalStateException
.
今天的 1.11 snapshot (and 2.1 snapshot,2.x 用户可以使用该修复程序。
我在大型 Web 应用程序中同时使用 OmniFaces 1.10 和 Apache MyFaces 2.2.6。当应用程序在生产中 运行 时,我在 Web 服务器 (Tomcat) 日志中收到以下形式的虚假异常:
java.lang.NullPointerException
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.put(ManagedBeanResolver.java:101)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.putInScope(ManagedBeanResolver.java:367)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:340)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:296)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
at org.apache.myfaces.view.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:431)
at org.apache.myfaces.view.facelets.tag.TagAttributeImpl.getBoolean(TagAttributeImpl.java:143)
at org.apache.myfaces.view.facelets.tag.jstl.core.ChooseWhenHandler.isTestTrue(ChooseWhenHandler.java:68)
at org.apache.myfaces.view.facelets.tag.jstl.core.ChooseHandler.apply(ChooseHandler.java:182)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:55)
at org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate.apply(ComponentTagHandlerDelegate.java:373)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:50)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:195)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:46)
at org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:520)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:574)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:552)
at org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:240)
at org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
at org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
at org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:188)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(FaceletViewDeclarationLanguage.java:477)
at org.omnifaces.viewhandler.RestorableViewHandler.restoreView(RestorableViewHandler.java:80)
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
我确信这是一个问题,或者至少是应用程序中的边缘情况(例如,错误地使用了一些 bean 变量的 .xhtml 文件),但我无法在测试用例中重现它,而且以前的版本也从未发生过MyFaces 和 OmniFaces。
异常本身似乎被触发,因为 OmniFaces "RestorableViewHandler" 尝试恢复视图只是为了查看它是否包含应自动恢复的标签。当恢复的视图不包含标签时,它会丢弃(已经)恢复的视图。除了明显的性能问题外,这还会触发此 NullPointerException,所以我不想要这个,因此我正在寻找一种方法来完全禁用 RestorableViewHandler。我知道当我这样做时,我将无法使用标签 "enableRestorableView",但这没关系。
如果不修改 OmniFaces 源代码是不可能禁用它的。根据 issue 92 这已经通过让 <o:enableRestorableView>
在某处使用后设置应用程序范围的属性来解决,这样 RestorableViewHandler
可以决定是否尝试恢复视图。
请注意,我真的更喜欢动态注册 RestorableViewHandler
,但是当应用程序之前已经处理过请求时,不可能动态注册 ViewHandler
。 It would only cause an IllegalStateException
.
今天的 1.11 snapshot (and 2.1 snapshot,2.x 用户可以使用该修复程序。