Omnifaces cdi param与JSF 2.3之间的冲突

时间:2019-04-21 03:32:16

标签: jsf tomee omnifaces

在将服务器从tomee plume 7升级到tomee plume 8之后,我的Web应用程序遇到了Omnifaces cdi param问题。我使用裸骨Webapp进行了测试并确认了这一点。

我的豆子:

@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羽7基于Tomcat 8,Mojarra JSF 2.2,而TomEE羽8基于Tomcat 9,Mojarra JSF 2.3。当然,还有更多的区别,但是测试Web应用程序是如此简单,以至于影响我的应该仅是Tomcat和JSF版本,并且插入了SAME jar。

1 个答案:

答案 0 :(得分:1)

这不是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测试服务器从TomEE 7.0.4到TomEE 8.0.0-M2之后,我自己在OmniFaces中偶然发现了此问题。与您所观察到的完全相同的问题是在IT期间发生的。解决方法是disable bean验证。

记录下来,这是完整的堆栈跟踪:

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)