我正在努力让Deltaspikes @WindowScoped与TomEE合作(尝试过1.5.2,1.5.3-SNAPSHOT和1.6.0-SNAPSHOT)
这是一场非常小的战争,拥有deltaspike 0.4核心+ jsf依赖。
现在,我确实创建了一个像这样的HelloWorldBean:
@Named("HW")
@WindowScoped
public class HelloWorldBean implements PassivationCapable,Serializable{
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@PostConstruct
public void test() {
System.out.println("Bean did get constructed");
}
....
}
有一个空的beans.xml,空的faces-config.xml和一个非常小的web.xml。
在一个非常简单的页面上。
<h:form>
<h:inputText value="#{HW.name}"></h:inputText>
<h:commandButton value="Welcome Me" actionListener="#{HW.printIt}"></h:commandButton>
</h:form>
页面工作正常,windowId被添加到请求中,当我刷新页面时,我看到bean没有实例化(即test()只被调用一次)。 但是,一旦我按下commandButton,我就会得到一个ContextNotActiveException异常:
org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: Error reading 'name' on type de.glauche.beans.HelloWorldBean$$OwbNormalScopeProxy0
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:104)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:249)
at javax.faces.component.UIOutput.getValue(UIOutput.java:67)
at javax.faces.component.UIInput.getValue(UIInput.java:151)
at javax.faces.component.UIInput.validate(UIInput.java:618)
at javax.faces.component.UIInput.processValidators(UIInput.java:274)
at javax.faces.component.UIForm.processValidators(UIForm.java:213)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1427)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1427)
at javax.faces.component.UIViewRoot._processValidatorsDefault(UIViewRoot.java:1456)
at javax.faces.component.UIViewRoot.access$500(UIViewRoot.java:74)
at javax.faces.component.UIViewRoot$ProcessValidatorPhaseProcessor.process(UIViewRoot.java:1563)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1412)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:812)
at org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeLifecycleWrapper.execute(DeltaSpikeLifecycleWrapper.java:75)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: javax.el.ELException: Error reading 'name' on type de.glauche.beans.HelloWorldBean$$OwbNormalScopeProxy0
at javax.el.BeanELResolver.getValue(BeanELResolver.java:68)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:58)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.webbeans.el22.WrappedValueExpression.getValue(WrappedValueExpression.java:70)
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
... 35 more
Caused by: javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @WindowScoped does not exist within current thread
at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:299)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:88)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:70)
at de.glauche.beans.HelloWorldBean$$OwbNormalScopeProxy0.getName(de/glauche/beans/HelloWorldBean.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:64)
... 41 more
我错过了一些明显的东西吗?或者它是DeltaSpike中的错误? (或TomEE?)
答案 0 :(得分:2)
此异常表示未在WindowContext中设置windowId。您是否在片段中添加了正确的DeltaSpike标签?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ds="http://deltaspike.apache.org/jsf">
<h:head></h:head>
<h:body>
<ds:windowId/>
...
ds:windowId部分很重要。 您可以调试DeltaSpikeLifecycleWrapper #execute以查看windowId是否被正确检测到。