Omnifaces cdi 参数和 JSF 2.3 之间的冲突

Conflict between Omnifaces cdi param and JSF 2.3

我的网络应用程序在将服务器从 tomee plume 7 升级到 tomee plume 8 后遇到了 Omnifaces cdi 参数问题。我用裸机网络应用程序进行了测试并确认了这一点。

我的豆子:

@javax.faces.view.ViewScoped
@javax.inject.Named
public class Bean2 implements java.io.Serializable {
  @javax.inject.Inject @org.omnifaces.cdi.Param
  private String tag;
  private String tag2;

  @javax.annotation.PostConstruct
  public void init() {
    if (getTag() == null || getTag().length()==0) {
        setTag2("None injected");
    }
    else 
        setTag2(getTag() + " injected");
    // Getters and setters

}

我的 JSF 视图:

<h:body>
    Tag: <h:outputText value="#{bean2.tag}" />
    <br/>
    <p:inputText readonly="true" value="#{bean2.tag2}"/>
</h:body>

我试过http://localhost:8080/test/inject2.jsf?tag=ABC,但只成功了一次。随后的试验给出:

java.lang.IllegalArgumentException: Unknown property tag of class com.mycompany.Bean2
at org.apache.bval.jsr.job.ValidateProperty$FindDescriptor.handleProperty(ValidateProperty.java:216)
at org.apache.bval.jsr.job.ValidateProperty$WalkGraph.handleProperty(ValidateProperty.java:312)
Caused by: javax.el.ELException: Error reading [tag] on type [com.mycompany.Bean2$$OwbNormalScopeProxy0]
at javax.el.BeanELResolver.getValue(BeanELResolver.java:98)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELR...

如果我重新启动服务器,它也只能工作一次。

我的环境Java:openjdk版本“1.8.0_191”,Primefaces 6.1,Omnifaces 2.6.9。我知道使用 TomEE 的人不多,但为了提供信息,TomEE plume 7 基于 Tomcat 8,Mojarra JSF 2.2,而 TomEE plume 8 基于 Tomcat 9,Mojarra JSF 2.3。当然还有更多差异,但测试 Web 应用程序非常简单,影响我的应该是 Tomcat 和 JSF 版本,其中包含相同的 jar。

这不是 OmniFaces、JSF 或 CDI 中的错误。

这是 BVal(Apache 的 Bean 验证 (JSR303) 实现)中的错误。堆栈跟踪至少证实了这一点。它从 BVal 类.

中抛出异常

OmniFaces CDI @Param 注释具有在注入值之前自动执行 Bean 验证的功能。这在较旧的 BVal 版本和其他 BV 实现(例如 Hibernate Validator)中一直运行良好。

最好的办法是将此问题报告给 BVal 人员。同时,您可以通过在 @Param.

上禁用 BV 来解决此问题
@Inject @Param(disableBeanValidation=true)
private String tag;

upgrading the test server from TomEE 7.0.4 to TomEE 8.0.0-M2. Exactly the same problem as you've observed occurred during an IT. The fix was to disable bean 验证之后,我自己在 OmniFaces 中偶然发现了这个问题。

作为记录,这是完整的堆栈跟踪:

28-Apr-2019 12:18:37.479 SEVERE [http-nio-8080-exec-28] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [facesServlet] in context with path [/MultiViewsIT] threw exception [Unknown property secondPathParamAsInteger of class org.omnifaces.test.facesviews.multiviews.MultiViewsITBean] with root cause
java.lang.IllegalArgumentException: Unknown property secondPathParamAsInteger of class org.omnifaces.test.facesviews.multiviews.MultiViewsITBean
    at org.apache.bval.jsr.job.ValidateProperty$FindDescriptor.handleProperty(ValidateProperty.java:216)
    at org.apache.bval.jsr.job.ValidateProperty$WalkGraph.handleProperty(ValidateProperty.java:312)
    at org.apache.bval.jsr.util.PathNavigation$PathPosition.handleProperty(PathNavigation.java:324)
    at org.apache.bval.jsr.util.PathNavigation.parse(PathNavigation.java:218)
    at org.apache.bval.jsr.util.PathNavigation.navigateAndReturn(PathNavigation.java:176)
    at org.apache.bval.jsr.util.PathNavigation.navigate(PathNavigation.java:192)
    at org.apache.bval.jsr.job.ValidateProperty.<init>(ValidateProperty.java:490)
    at org.apache.bval.jsr.job.ValidateProperty.<init>(ValidateProperty.java:500)
    at org.apache.bval.jsr.job.ValidationJobFactory.validateValue(ValidationJobFactory.java:76)
    at org.apache.bval.jsr.ValidatorImpl.validateValue(ValidatorImpl.java:65)
    at org.apache.bval.jsr.CascadingPropertyValidator.validateValue(CascadingPropertyValidator.java:99)
    at org.omnifaces.util.Platform.validateBeanProperty(Platform.java:129)
    at org.omnifaces.cdi.param.ParamProducer.doBeanValidation(ParamProducer.java:403)
    at org.omnifaces.cdi.param.ParamProducer.validateBean(ParamProducer.java:252)
    at org.omnifaces.cdi.param.ParamProducer.validateValues(ParamProducer.java:223)
    at org.omnifaces.cdi.param.ParamProducer.produce(ParamProducer.java:103)
    at org.omnifaces.cdi.param.DynamicParamValueProducer.create(DynamicParamValueProducer.java:72)
    at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(ThirdpartyBeanImpl.java:97)
    at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:68)
    at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:125)
    at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:813)
    at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:673)
    at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:100)
    at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:65)
    at org.apache.webbeans.portable.InjectionTargetImpl.injectFields(InjectionTargetImpl.java:227)
    at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:213)
    at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:203)
    at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:126)
    at org.apache.webbeans.component.ManagedBean.create(ManagedBean.java:66)
    at org.apache.webbeans.context.creational.BeanInstanceBag.create(BeanInstanceBag.java:76)
    at org.apache.webbeans.context.AbstractContext.getInstance(AbstractContext.java:159)
    at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:125)
    at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:101)
    at org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler.getContextualInstance(RequestScopedBeanInterceptorHandler.java:76)
    at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:71)
    at org.omnifaces.test.facesviews.multiviews.MultiViewsITBean$$OwbNormalScopeProxy0.getFirstPathParamAsString(org/omnifaces/test/facesviews/multiviews/MultiViewsITBean.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:94)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:62)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:190)
    at org.apache.webbeans.el22.WrappedValueExpression.getValue(WrappedValueExpression.java:68)
    at org.apache.myfaces.view.facelets.el.ELText$ELTextVariable.writeText(ELText.java:218)
    at org.apache.myfaces.view.facelets.compiler.TextInstruction.write(TextInstruction.java:45)
    at org.apache.myfaces.view.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:46)
    at org.apache.myfaces.view.facelets.compiler.UILeaf.encodeAll(UILeaf.java:491)
    at javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:551)
    at javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:551)
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1897)
    at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:315)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:73)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:73)
    at org.omnifaces.viewhandler.OmniViewHandler.renderView(OmniViewHandler.java:121)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:73)
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:117)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:266)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.omnifaces.facesviews.FacesViewsForwardingFilter.filterExtensionLessToExtension(FacesViewsForwardingFilter.java:180)
    at org.omnifaces.facesviews.FacesViewsForwardingFilter.filterExtensionLess(FacesViewsForwardingFilter.java:137)
    at org.omnifaces.facesviews.FacesViewsForwardingFilter.filterExtensionLess(FacesViewsForwardingFilter.java:123)
    at org.omnifaces.facesviews.FacesViewsForwardingFilter.doFilter(FacesViewsForwardingFilter.java:84)
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)