1 2 Previous Next 21 Replies Latest reply on Oct 19, 2010 4:46 AM by kwutzke Go to original post
      • 15. Re: Component not instantiated?
        kwutzke

        Appendix:


        Of course, I also have a standard HTTP servlet, is there anything I might try from that to debug this? Instantiating a SeasonListQuery from there resulted in:


        javax.persistence.TransactionRequiredException: no transaction is in progress
        ...



        I then patched the following around the constructor call in HttpServlet.doGet():


                FacesContextFactory facesContextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
                LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
                ServletContext servletContext = getServletConfig().getServletContext();
                String lifecycleId = servletContext.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
                
                javax.faces.lifecycle.Lifecycle lifecycle = lifecycleFactory.getLifecycle(lifecycleId != null ? lifecycleId : LifecycleFactory.DEFAULT_LIFECYCLE);
                
                FacesContext fc = facesContextFactory.getFacesContext(servletContext, request, response, lifecycle);
        
                UserTransaction userTx = (UserTransaction)org.jboss.seam.Component.getInstance("org.jboss.seam.transaction.transaction");
                
                try
                {
                    userTx.setTransactionTimeout(600);
                    userTx.begin();
                }
                catch ( Exception e )
                {
                    out.println(e.getStackTrace());
                }
                
                // if the entity manager is created before the transaction is started (ie. via Injection) then it must join the transaction
                em.joinTransaction();
                
                SeasonListQuery slq = new SeasonListQuery();
                
                em.flush();   //logs will show an insert at this point
                
                try
                {
                    userTx.commit();
                }
                catch ( Exception e )
                {
                    out.println(e.getStackTrace());
                }
        



        It gets rid of the TransactionException but leaves me with another stack trace:


        java.lang.IllegalStateException: No application context active
            org.jboss.seam.Component.forName(Component.java:1945)
            org.jboss.seam.Component.getInstance(Component.java:2005)
            org.jboss.seam.Component.getInstance(Component.java:1983)
            org.jboss.seam.Component.getInstance(Component.java:1977)
            org.jboss.seam.Component.getInstance(Component.java:1972)
            com.kawoolutions.bbstats.servlet.BasketballStatsServlet.doGet(BasketballStatsServlet.java:254)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        



        From the stack trace you can see that Seam is kicking in. I'm not sure if this means anything??? Seam working, Facelets/EL not?


        Karsten

        • 16. Re: Component not instantiated?
          kwutzke

          OK, I got an instance of a Seam component from an HttpServlet via the following code:


                  FacesContextFactory facesContextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
                  LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
                  ServletContext servletContext = getServletConfig().getServletContext();
                  String lifecycleId = servletContext.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
                  
                  javax.faces.lifecycle.Lifecycle lifecycle = lifecycleFactory.getLifecycle(lifecycleId != null ? lifecycleId : LifecycleFactory.DEFAULT_LIFECYCLE);
                  
                  FacesContext fc = facesContextFactory.getFacesContext(servletContext, request, response, lifecycle);
                  Lifecycle.beginCall();
          
                  UserTransaction userTx = (UserTransaction)org.jboss.seam.Component.getInstance("org.jboss.seam.transaction.transaction");
                  
                  try
                  {
                      userTx.setTransactionTimeout(600);
                      userTx.begin();
                  }
                  catch ( Exception e )
                  {
                      out.println(e.getStackTrace());
                  }
                  
                  // if the entity manager is created before the transaction is started (ie. via Injection) then it must join the transaction
                  //em.joinTransaction();//*/
                  
                  //do stuff    
                  
                  SeasonListQuery slq = new SeasonListQuery();
                  
                  out.println("<p>" + slq.getEjbql() + "</p>");
          
                  List<Season> lsSeasons = slq.getResultList();
                  
                  out.println("<ul>");
                  for ( Season se : lsSeasons )
                  {
                      out.println("<li>Season " + se.getStartYear() + "</li>");
                  }
                  out.println("</ul>");//*/
                  
                  try
                  {
                      userTx.commit();
                  }
                  catch ( Exception e )
                  {
                      out.println(e.getStackTrace());
                  }
                  
                  Lifecycle.endCall();
          



          The code works fine, until calling getResultList or getResultCount on the component. Doing


          List<Season> lsSeasons = slq.getResultList();



          results in:


          java.lang.NullPointerException
               org.jboss.seam.transaction.AbstractUserTransaction.enlist(AbstractUserTransaction.java:73)
               org.jboss.seam.framework.EntityQuery.joinTransaction(EntityQuery.java:236)
               org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:179)
               org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:79)
               org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:71)
               com.kawoolutions.bbstats.servlet.BasketballStatsServlet.doGet(BasketballStatsServlet.java:280)
               javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
               javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          



          Hmmm... I'm beginning to give up.


          I'm wondering: if I can't get even the simplest setup going, which future does Seam have for me? sigh


          Karsten


          PS: need more beer

          • 17. Re: Component not instantiated?
            lvdberg

            Hi,


            You need to check all the configurations. It's a pity you're not using the existing tools for Seam for Eclipse which makes the job a lot easire. Let's see if the following helps you:


            Addition to faces-config.xml under WEB-INF


            <?xml version="1.0"?>
            <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xi="http://www.w3.org/2001/XInclude"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
             
             <application>
             <locale-config>
                      <default-locale>en</default-locale>
                      <supported-locale>en</supported-locale>
                      <supported-locale>es</supported-locale>
                      <supported-locale>nl</supported-locale>
                      <supported-locale>ca_ES</supported-locale>
                      <supported-locale>en_GB</supported-locale>
                      <supported-locale>en_US</supported-locale>
                 </locale-config>
              <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
             </application>
            </faces-config>



            In web.xml




                 <context-param>
                      <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                      <param-value>.xhtml</param-value>
                 </context-param>
                 <context-param>
                      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                      <param-value>server</param-value>
                 </context-param>



            Also in web.xml


                
            
                <filter>
                    <filter-name>Seam Filter</filter-name>
                    <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
                </filter>
                <filter-mapping>
                    <filter-name>Seam Filter</filter-name>
                    <url-pattern>*.faces</url-pattern>
                </filter-mapping>
                <listener>
                    <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
                </listener>
                <servlet>
                    <servlet-name>Seam Resource Servlet</servlet-name>
                    <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
                </servlet>
                <servlet>
                    <servlet-name>Faces Servlet</servlet-name>
                    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                    <load-on-startup>1</load-on-startup>
                </servlet>
                <servlet>
                    <servlet-name>Document Store Servlet</servlet-name>
                    <servlet-class>org.jboss.seam.document.DocumentStoreServlet</servlet-class>
                </servlet>
            
                 <!-- Servlet Mappings -->
                 <servlet-mapping>
                      <servlet-name>Faces Servlet</servlet-name>
                      <url-pattern>*.faces</url-pattern>
                 </servlet-mapping>
            
                 <servlet-mapping>
                      <servlet-name>Seam Resource Servlet</servlet-name>
                      <url-pattern>/seam/resource/*</url-pattern>
                 </servlet-mapping>
            
                 <servlet-mapping>
                      <servlet-name>Document Store Servlet</servlet-name>
                      <url-pattern>*.pdf</url-pattern>
                 </servlet-mapping>
                 <servlet-mapping>
                      <servlet-name>Document Store Servlet</servlet-name>
                      <url-pattern>*.csv</url-pattern>
                 </servlet-mapping>
                 <servlet-mapping>
                      <servlet-name>Document Store Servlet</servlet-name>
                      <url-pattern>*.xls</url-pattern>
                 </servlet-mapping>
                 <servlet-mapping>
                      <servlet-name>Document Store Servlet</servlet-name>
                      <url-pattern>*.rtf</url-pattern>
                 </servlet-mapping>
            
            
            



            A basic configuration in components.xml under WEB-INF (depending what you need) and last BUT NOT LEAST a seam.properties file (can be empty) in the classes sub-dir of WEB-INF. This last one is really important because it is used by Seam to locate Seam enhanced classes in the classpath. If that properties file is not present the dir will be skipped.


            Hopefully this helps.


            Leo




            • 18. Re: Component not instantiated?
              kwutzke

              Holy cow! Adding an empty seam.properties to the WEB-INF/classes seems to do the job. It is the first time now my entity components are instantiated (I also learned that abstract entity classes shouldn't be @Name'd, which makes sense. I have to change my code generator plugin to skip abstract classes... ;-) )


              I'm now back to the FacesServlet, using a seasonListQuery EL expression, which leads to an EntityManager NPE:


              javax.servlet.ServletException: Could not instantiate Seam component: seasonListQuery
                  javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
              
              root cause
              
              org.jboss.seam.InstantiationException: Could not instantiate Seam component: seasonListQuery
                  org.jboss.seam.Component.newInstance(Component.java:2144)
                  org.jboss.seam.Component.getInstance(Component.java:2021)
                  org.jboss.seam.Component.getInstance(Component.java:1983)
                  org.jboss.seam.Component.getInstance(Component.java:1977)
                  org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
                  org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
                  org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
                  org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
                  javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
                  com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
                  org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
                  org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
                  org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                  com.sun.facelets.el.ELText$ELTextVariable.toString(ELText.java:174)
                  com.sun.facelets.el.ELText$ELTextComposite.toString(ELText.java:115)
                  com.sun.facelets.compiler.CommentInstruction.write(CommentInstruction.java:38)
                  com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
                  com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
                  javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
                  com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                  com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
                  com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                  com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                  javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
              
              root cause
              
              java.lang.IllegalStateException: entityManager is null
                  org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:41)
                  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                  java.lang.reflect.Method.invoke(Unknown Source)
                  org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                  org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                  org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                  org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                  org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                  org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
                  org.jboss.seam.util.Work.workInTransaction(Work.java:47)
                  org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
                  org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                  org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                  org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                  org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                  org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                  org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                  com.kawoolutions.bbstats.semidao.SeasonListQuery_$$_javassist_seam_2.validate(SeasonListQuery_$$_javassist_seam_2.java)
                  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                  java.lang.reflect.Method.invoke(Unknown Source)
                  org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                  org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                  org.jboss.seam.Component.callComponentMethod(Component.java:2249)
                  org.jboss.seam.Component.callCreateMethod(Component.java:2172)
                  org.jboss.seam.Component.newInstance(Component.java:2132)
                  org.jboss.seam.Component.getInstance(Component.java:2021)
                  org.jboss.seam.Component.getInstance(Component.java:1983)
                  org.jboss.seam.Component.getInstance(Component.java:1977)
                  org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
                  org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
                  org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
                  org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
                  javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
                  com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
                  org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
                  org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
                  org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                  com.sun.facelets.el.ELText$ELTextVariable.toString(ELText.java:174)
                  com.sun.facelets.el.ELText$ELTextComposite.toString(ELText.java:115)
                  com.sun.facelets.compiler.CommentInstruction.write(CommentInstruction.java:38)
                  com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
                  com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
                  javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
                  com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                  com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
                  com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                  com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                  javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
              



              Karsten

              • 19. Re: Component not instantiated?
                kwutzke

                Thanks so much for helping on this issue, Leo.


                I have opened a follow-up thread to continue setting up Seam manually on Tomcat 6 here:


                http://seamframework.org/Community/ConfiguringPersistenceUnitTomcat6EmbeddedJBossJavaxnamingNameNotFoundExceptionNameJavacompIsNotBoundInThisContext


                I really hope I get over this last hurdle...


                Karsten

                • 20. Re: Component not instantiated?
                  lvdberg

                  Hi,


                  I'm glad that everything is starting to work now. But after rereading this thread I need to make some staments. To begin, some of your own quotes in this thread.




                  It's my first time trying to build a Seam app. Even though I have Seam in Action,





                  If so, there's some information missing in the Seam manual and Seam in Action as to how to correctly implement EntityQuery subclasses!




                  There is something wrong in my setup, I just don't know what it is. I'm beginning to believe it's not the Java code...




                  I don't use Eclipse for anything but to show me the errors etc. while typing.




                  Holy cow! Adding an empty seam.properties to the WEB-INF/classes seems to do the job.


                  I don't want to seem annoying, but I never, never have understood people who want to complicate things more than necessary and man, you're doing that. I think the best way to complicate it even more is to do everything blindfolded.


                  Seam is for starters really complex and JBoss has provided excellent Eclipse tools to learn Seam without much effort. Please use them, and - even more important - READ THE SEAM IN ACTION BOOK (and don't skip the first chapters), THE FREE DOCUMENTATION AND PRACTICE WITH THE EXAMPLES!!!


                  I sincerely hope you're not doing this work for a living.


                  Leo


                  P.S. I am sorry but I can't waste any more time on this matter, so succes with your TomCat configuration.




                  • 21. Re: Component not instantiated?
                    kwutzke

                    Yes, I just don't like builders like seam-gen, they give me the feeling of not having under control what I'm doing. I need that kind of minimalism, also to learn what is needed and why. My current webapp is clearly a test app with its only purpose to learn Seam/JPA/Hibernate. I'm planning to use Seam for future projects, but until then I must have learned Seam a lot better than the 25% I'm currently at.


                    And yes, the only chapters of Seam in Action I'm currently focused on are ch. 3-7, the persistence stuff in ch. 8-10 was/is a lot easier for me starting Seam (I still think the order of chapters is wrong, persistence after the JSF/Seam lifecycle stuff). Obviously, there's still a lot to learn (I'm from the desktop/Swing app world...), however, I will punch myself through Seam, even if I've actually never put up an EJB/JavaEE webapp. I'm not that pessimistic on using Seam for a living in the near future, but that's another story.


                    Again, thanks for helping on my setup issues.
                    Karsten

                    1 2 Previous Next