6 Replies Latest reply on Apr 29, 2011 10:04 AM by piklos

    Seam-faces with tomcat

    piklos

      When depolying a simple war with faces-module 3.0.0-Final on tomcat (regardles of whether it is 6 or 7).
      The application seems not to be able to start because of the




       org.jboss.seam.solder.beanManager.BeanManagerUnavailableException: Failed to locate BeanManager using any of these providers: org.jboss.seam.solder.beanManager.DefaultJndiBeanManagerProvider(11), org.jboss.seam.solder.beanManager.ServletContainerJndiBeanManagerProvider(10)



      I only have one bean in the application and depending on the scope of that bean different things can happen:
      1) ApplicationScoped and RequestScope seems to work without problem.
      2) However all other scopes (ViewScoped,SessionScoped,RenderScoped...) fail with the above mentioned exception.


      If i remove the seam-faces module from my classpath (and from the web.xml in tomcat 6 case) all the scopes work without any problems.
      This makes me suspcious on seam-faces module.


      I would try to use 3.0.1.Final version, but it is not available on the
      JBoss Community Repository
      (as it stands on the Faces module page).


        • 1. Re: Seam-faces with tomcat
          bleathem

          Seam Faces 3.0.1 is now available in the maven repositories - sorry for the delay.


          What you describe does indeed sound odd.  Can you please file a jira issue, and attach a simple example demonstrating the failing behaviour you describe?

          • 2. Re: Seam-faces with tomcat
            piklos

            Jirra issue
            I hope its clear enough.

            • 3. Re: Seam-faces with tomcat
              piklos

              The problem is still there even with 3.0.1-Final version.

              • 4. Re: Seam-faces with tomcat
                fup

                Testing the example attached to the Jira issue I get the following exception (before getting a BeanManagerUnavailableException):


                org.jboss.weld.exceptions.DefinitionException: WELD-000072 Managed bean declaring a passivating scope must be passivation capable.


                Passivating scopes (e.g. session or conversation) require managed beans to implement Serializable. If I implement the interface for the one and only bean in the example, the application starts fine. Application and request scopes worked all along, since they aren't passivating scopes.


                (I guess, the issue was not Tomcat related.)

                • 5. Re: Seam-faces with tomcat
                  piklos

                  Yes you are right. It was my mistake after all. The bug can probably be closed.


                  However i found something different that i hope somebody can help me with.


                  When i depoy my application to servlet in one point it says




                  INFO: Tomcat detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported

                  But the seam faces listener:



                  public class BeanManagerServletContextListener implements ServletContextListener {
                      public static final String BEANMANAGER_SERVLETCONTEXT_KEY = "org.jboss.seam.faces.javax.enterprise.spi.BeanManager";
                  
                      @Inject
                      private BeanManager beanManager;
                  
                      public void contextDestroyed(ServletContextEvent sce) {
                      }
                  
                      public void contextInitialized(ServletContextEvent sce) {
                          sce.getServletContext().setAttribute(BEANMANAGER_SERVLETCONTEXT_KEY, beanManager);
                      }
                  
                  }



                  Tries to inject BeanManager there and to put it into the servlet context with accesible via key. That bean manager is always null, i am guessing that that is so because injection doesn't work with listeners, as stated above.


                  Now when you have PrettyFaces filter in your web.xml. While beaing initilized that filter calls loadConfiguration method on a RewriteConfiguration class.


                  That class looks like this on seam-faces 3.0.1




                  @Requires("com.ocpsoft.pretty.faces.spi.ConfigurationProvider")
                  public class RewriteConfiguration implements ConfigurationProvider {
                      public static final String PRETTYFACES_CONFIG_SERVLETCONTEXT_KEY = "org.jboss.seam.faces.com.ocpsoft.pretty.faces.spi.ConfigurationProvider";
                      
                      @Override
                      public PrettyConfig loadConfiguration(ServletContext sc) {
                          WebXmlParser webXmlParser = new WebXmlParser();
                          try {
                              webXmlParser.parse(sc);
                          } catch (IOException ex) {
                              throw new RuntimeException(ex);
                          } catch (SAXException ex) {
                              throw new RuntimeException(ex);
                          }
                          BeanManager beanManager = (BeanManager) sc.getAttribute(BeanManagerServletContextListener.BEANMANAGER_SERVLETCONTEXT_KEY);
                          ViewConfigStore store = BeanManagerUtils.getContextualInstance(beanManager, ViewConfigStore.class);
                         ...
                  ...




                  However since bean manager is always null in the servlet context this class always explodes with null pointer exception. Apperently this class works only when com.ocpsoft.pretty.faces.spi.ConfigurationProvider is present, which is my case.
                  Do i need to add seam servlet?? Or what?

                  • 6. Re: Seam-faces with tomcat
                    piklos

                    I changed



                     public class BeanManagerServletContextListener implements ServletContextListener {
                        public static final String BEANMANAGER_SERVLETCONTEXT_KEY = "org.jboss.seam.faces.javax.enterprise.spi.BeanManager";
                    
                        @Inject
                        private BeanManager beanManager;
                    
                        public void contextDestroyed(ServletContextEvent sce) {
                        }
                    
                        public void contextInitialized(ServletContextEvent sce) {
                             if (beanManager == null){
                                  String name = Listener.class.getPackage().getName() + "." + BeanManager.class.getName();
                                  beanManager = (BeanManager)sce.getServletContext().getAttribute(name);
                             }
                            sce.getServletContext().setAttribute(BEANMANAGER_SERVLETCONTEXT_KEY, beanManager);
                        }
                    
                    }



                    Now although the injection is always null the bean manager is found in the servlet context.