Question

I'm struggeling how to get Deltaspikes @WindowScoped working with TomEE (did try 1.5.2, 1.5.3-SNAPSHOT and 1.6.0-SNAPSHOT)

Its a very minimal war, with deltaspike 0.4 core+jsf dependencies.

Now, i did create a HelloWorldBean like this:

@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");
    }
....
}

There's an empty beans.xml, empty faces-config.xml and a very minimal web.xml.

on a very simple page i have.

<h:form>
           <h:inputText value="#{HW.name}"></h:inputText>
       <h:commandButton value="Welcome Me" actionListener="#{HW.printIt}"></h:commandButton>
        </h:form>

The page works fine, a windowId is added to the request and when i refresh the page i see that the bean is not instanciated (i.e. test() gets only called once). But as soon i press the commandButton i get an ContextNotActiveException exception:

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

Am i missing something obvious? Or is it a bug in DeltaSpike? (or TomEE?)

Was it helpful?

Solution

This Exception indicates that the windowId is not set in the WindowContext. Did you add the proper DeltaSpike tag into your fragment?

<!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/>
...

The ds:windowId part is important. You can debug into DeltaSpikeLifecycleWrapper#execute to see if the windowId gets detected properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top