1 2 Previous Next 16 Replies Latest reply on Nov 6, 2008 1:51 PM by Shane Bryzak

    Backing bean not picked up by Seam during startup of webapp

    Coen Damen Novice

      Hi,


      I am new to Seam, I am having a problem to get Seam pickup a backing bean in the WAR project. The backing bean is in src/main/java/some.package


      This is the code.


      @Stateless
      @Name("distributorBacking")
      public class DistributorBacking {
      
              CalculatorRemote calculator;
      
              public String getTekst() {
      
                      try {
                              Properties properties = new Properties();
                              properties.put("java.naming.factory.initial",
                                              "org.jnp.interfaces.NamingContextFactory");
                              properties.put("java.naming.factory.url.pkgs",
                                              "org.jboss.naming:org.jnp.interfaces");
                              properties.put("java.naming.provider.url", "jnp://localhost:1099");
                              Context ctx = new InitialContext(properties);
      
                              calculator = (CalculatorRemote) ctx
                                              .lookup("umbrella/CalculatorImpl/remote");
                      } catch (NamingException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                      }
      
                      return calculator.getOk();
              }
      }
      
      



      The following text should be shown in the jsf page


      
      <li>The value of the value is 
          <h:outputText value="#{distributorBacking.tekst}"></h:outputText></li>
      
      



      I have a distributed environment, so one Webserver (JBoss 4.2.2) and one (AppServer JBoss 4.2.3) but I am still working only on the 4.2.2. So the lookup is just for testing.


      The issue is that if I put the managed-bean in the faces-config.xml, everything works fine. But in Seam I shouldn't have to do that.


      So, why is the backing-bean not picked up at startup time? I see in the JBoss logs that it creates components for all beans, but not this one. Perhaps the location of the bean is invalid??



      Hope anyone knows the issue, thanks,
      Coenos

        • 1. Re: Backing bean not picked up by Seam during startup of webapp
          Tobias Hill Newbie

          So ... given that this is an EJB, did you create a local interface for it?

          • 2. Re: Backing bean not picked up by Seam during startup of webapp
            Coen Damen Novice

            Hmm ok I didn't do that. I just created a POJO with a @Name in the WAR.


            However, when I add an interface with @Local like this:


            
            @Local
            public interface DistributorBackingIF {
            
                 public String getTekst();
            }
            
            



            It doesn't get picked up by Seam either. Note that my  jndi-pattern in the components.xml is


            
            <!--  This should address all remote EJBS -->
                 <core:init debug="true" jndi-pattern="umbrella/#{ejbName}/remote" />
            
            



            Maybe the problem is that the backing bean is in the War project ?


            Hope you know the answer,
            Coenos

            • 3. Re: Backing bean not picked up by Seam during startup of webapp
              Shane Bryzak Master

              Do you have an empty seam.properties in your archive?

              • 4. Re: Backing bean not picked up by Seam during startup of webapp
                Coen Damen Novice

                Right !! That's it!


                I built my Project with Seam and Maven2, not using seam-gen, so there was no file present there by default.


                And of course, when searching through the Seam documentation, I found the Don't forget! paragraph concerning this issue :)


                Thanks a lot!
                Coenos

                • 5. Re: Backing bean not picked up by Seam during startup of webapp
                  Coen Damen Novice

                  Coen Damen wrote on Nov 06, 2008 09:29:


                  Right !! That's it!

                  I built my Project with Seam and Maven2, not using seam-gen, so there was no file present there by default.

                  And of course, when searching through the Seam documentation, I found the Don't forget! paragraph concerning this issue :)

                  Thanks a lot!
                  Coenos



                  I mean that I found the Don't forget! after you triggered me to place the file there..........

                  • 6. Re: Backing bean not picked up by Seam during startup of webapp
                    Coen Damen Novice

                    Hmm wait a sec, now I am getting a stacktrace saying the component can't be instantiated??


                     
                    
                    org.jboss.seam.InstantiationException: Could not instantiate Seam component: distributorBacking
                         at org.jboss.seam.Component.newInstance(Component.java:2066)
                         at org.jboss.seam.Component.getInstance(Component.java:1948)
                         at org.jboss.seam.Component.getInstance(Component.java:1910)
                         at org.jboss.seam.Component.getInstance(Component.java:1904)
                         at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
                         at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
                         at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
                         at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
                         at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
                         at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
                         at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
                         at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
                         at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                         at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                         at javax.faces.component.UIOutput.getValue(UIOutput.java:173)
                         at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:189)
                         at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:320)
                         at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
                         at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
                         at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286)
                         at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                         at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
                         at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
                         at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
                         at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
                         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
                         at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                         at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
                         at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
                         at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                         at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                         at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:51)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                         at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                         at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                         at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                         at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                         at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
                         at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                         at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                         at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                         at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                         at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                         at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                         at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                         at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                         at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                         at java.lang.Thread.run(Thread.java:595)
                    Caused by: javax.naming.NameNotFoundException: DistributorBacking not bound
                         at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
                         at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
                         at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
                         at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
                         at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
                         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
                         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
                         at javax.naming.InitialContext.lookup(InitialContext.java:351)
                         at org.jboss.seam.Component.instantiateSessionBean(Component.java:1327)
                         at org.jboss.seam.Component.instantiate(Component.java:1291)
                         at org.jboss.seam.Component.newInstance(Component.java:2044)
                         ... 74 more
                    
                    



                    Although I see it is created during deployment (???).


                    • 7. Re: Backing bean not picked up by Seam during startup of webapp
                      Shane Bryzak Master

                      Er hang on, you initially said that it was a war project, and yet it is a @Stateless bean?  If you want to use EJB then the classes need to go in a jar, which in turn need to go in an ear.

                      • 8. Re: Backing bean not picked up by Seam during startup of webapp
                        Coen Damen Novice

                        Yes,


                        I have two projects, a WAR and an EJB. The War is to be deployed on a webserver, and the EJB is to be deployed on an App server.


                        I want the following distributed flow:


                        JSF (Web) --to-- Backing (Managed) Bean (Web, instantiated by Seam) --to-- Remote Session facade EJB (App) --to-- Entity Bean (App) --to-- Database


                        This all works, but I want Seam to recognize my Managed Bean and I want to be able to use it in my JSF page. I now have it working that Seam picks up the bean but I somehow can't instantiate it( ????).


                        Hope you know a solution!
                        Coenos

                        • 9. Re: Backing bean not picked up by Seam during startup of webapp
                          Shane Bryzak Master

                          So is DistributorBacking a POJO?  The log suggests that it isn't.  On a different subject, is there a particular reason why you want to use such a separated architecture?  It's not very scalable.

                          • 10. Re: Backing bean not picked up by Seam during startup of webapp
                            Coen Damen Novice

                            Yes, it's just a POJO, here's the code:


                             
                            
                            @Stateless
                            @Name("distributorBacking")
                            public class DistributorBacking{
                            
                                    CalculatorRemote calculator;
                            
                                    public String getTekst() {
                            
                                            try {
                                                    Properties properties = new Properties();
                                                    properties.put("java.naming.factory.initial",
                                                                    "org.jnp.interfaces.NamingContextFactory");
                                                    properties.put("java.naming.factory.url.pkgs",
                                                                    "org.jboss.naming:org.jnp.interfaces");
                                                    properties.put("java.naming.provider.url", "jnp://localhost:1099");
                                                    Context ctx = new InitialContext(properties);
                            
                                                    calculator = (CalculatorRemote) ctx
                                                                    .lookup("umbrella/CalculatorImpl");
                                                    
                                                    return calculator.getOk();
                                            } catch (NamingException e) {
                                                    // TODO Auto-generated catch block
                                                    e.printStackTrace();
                                            }
                                            
                                            return "SOMETHING WENT WRONG";
                            
                                            
                                    }
                            }
                            
                            



                            Also in the JBOSS startup logs I see the component is created:


                            
                            10:29:47,515 INFO  [STDOUT] 10:29:47,515 INFO  [Component] Component: distributorBacking, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: com.*****.umbrella.distributor.backing.DistributorBacking, JNDI: umbrella/DistributorBacking
                            
                            



                            When I run the JSF page however, the Exception occurs.


                            • 11. Re: Backing bean not picked up by Seam during startup of webapp
                              Shane Bryzak Master

                              That's not a POJO, remove the @Stateless annotation.

                              • 12. Re: Backing bean not picked up by Seam during startup of webapp
                                Coen Damen Novice

                                Ah right, I forgot to remove the @stateless tag because I was tweaking and tweaking......


                                I then got a classcastexception which I could solve by adding /remote to the lookup name and I changed the jndi pattern in components.xml and now it is all working !


                                Thanks a lot!
                                Cheers,
                                Coenos

                                • 13. Re: Backing bean not picked up by Seam during startup of webapp
                                  Coen Damen Novice

                                  By the way, the architecture is defined as such, because the client wants it this way. They have a webserver and several app servers. So scaling will be done only on the Appserver side.


                                  Do you have any suggestions why this is not a scalable architecture ?


                                  Thanks,
                                  Coen

                                  • 14. Re: Backing bean not picked up by Seam during startup of webapp
                                    Shane Bryzak Master

                                    A couple of things, firstly if you only have one web server then that's a single point of failure, secondly, adding an extra tier that requires additional network communication reduces scalability.  Also, you lose many of the benefits that Seam gives you by splitting the tiers, for example you can't reference your model components directly from your view.

                                    1 2 Previous Next