9 Replies Latest reply on Sep 4, 2009 2:21 AM by H G

    JSF component bindings and EAR classloader

    H G Newbie

      Hi,


      I'm trying to implement a dynamic HtmlDropDownMenu, so from the view in a facelet I have the next code:


      <a4j:form>
        <rich:dropDownMenu binding="#{mDevice.menu}" value="File" />
       </a4j:form>



      This is the seam component:


      @Name("mDevice")
      @Scope(ScopeType.EVENT)
      @AutoCreate
      public class MDevice  implements Serializable {
         
          private HtmlDropDownMenu menu;
      
          public HtmlDropDownMenu getMenu() {
      
          menu = new HtmlDropDownMenu();
              HtmlOutputLabel hol = new HtmlOutputLabel();
              HtmlOutputText hot = new HtmlOutputText();
              hot.setValue("Some text");
              HtmlGraphicImage hgi = new HtmlGraphicImage();
              hgi.setUrl("img/some_image.gif");
              hgi.setStyle("vertical-align: bottom;");
              hol.getChildren().add(hot);
              hol.getChildren().add(hgi);
              menu.getFacets().put("label", hol);
                         
              HtmlMenuItem hmi = new HtmlMenuItem();
              hmi.setValue("Some text");
              menu.getChildren().add(hmi);
             
              hmi = new HtmlMenuItem();
              hmi.setValue("Another text");
              menu.getChildren().add(hmi);
             
             
      
              return menu;
          }
      
          public void setMenu(HtmlDropDownMenu menu) {
              this.menu = menu;
          }
      
      }



      Mi problem start with the fact that I'm using a EAR. The project was created with the seam-gen, so as richfaces-ui.jar and richfaces-impl.jar can be found in WAR/WEB-INF/lib (as I can read this is because of architecture decision, separating layers, fine).


      On the other hand the seam component mDevice is located in a package in ejbModule and can't see richfaces-ui.jar and richfaces-impl.jar so on build is advertising the missing classes.



      I try adding the reference to the richfaces-ui.jar and richfaces-impl.jar from the WAR to the java build path of the ejb. That doesn't work, because of initialization were created two instances of each jar, so ERROR is raised related with org.jboss.seam.servlet.SeamListener.


      My question is, what is the  better way to resolve this, without much changes on the the classloader configuration  and maintaining the layer structure as possible?




        • 1. Re: JSF component bindings and EAR classloader
          Stuart Douglas Master

          Move the richfaces jars out of web-inf/lib and into the root of the ear.

          • 2. Re: JSF component bindings and EAR classloader
            H G Newbie

            Thank You for the reply.


            This is my EAR structure:




            app-ear
                  :
                  .settings(inside org.eclipse.wst.common.commponent,
                  :                org.eclipse.wst.common.project.core.xml)
                  :
                  EarContent
                            :
                            META-INF(inside application.xml andjboss-app.xml)
                            :
                            antlr-runtime.jar
                            drools-compiler.jar
                            drools-core.jar
                      jboss-el.jar
                      jboss-seam.jar
                      jbpm-jpdl.jar
                      mvel14.jar
                            richfaces-api.jar
                 resources(inside app-ds.xml)
                 .project



            I tried to move richfaces-ui.jar and richfaces-impl.jar to the:


            1. Root of app-ear - the seam component mDevice can't see the jars

            2. Root of EarContent - the seam component mDevice can't see the jars

            3. After that tried with changes in the MANIFEST.MF from WAR/WebContent/META-INF adding in the final both jars (testing with 1, after with 2 structure) - without succsess the seam component mDevice can't see the jars



            This is my original MANIFEST.MF from WAR/WebContent/META-INF



            Manifest-Version: 1.0
            Class-Path: app-ejb.jar 
             antlr-runtime.jar 
             drools-compiler.jar 
             drools-core.jar 
             jboss-el.jar 
             jboss-seam.jar 
             jbpm-jpdl.jar 
             mvel14.jar 
             richfaces-api.jar




            I'm using JBoss Developer Studio Version: 2.0.0.GA
                      Build id: R200903141247-H4
                      Seam Tools Version: 3.0.1.GA-R200905070146-H18
                      Seam 2.1.2
                      Jboss 5.1

            • 3. Re: JSF component bindings and EAR classloader
              Leo van den berg Master

              Try to put the libs in the server lib directory. Works fine for me, but is not a good solution if you want to use separate WAR-files with different Rich-versions.


              • 4. Re: JSF component bindings and EAR classloader
                Stuart Douglas Master

                If you do have multiple projects with different versions you have to put the rf jars in application.xml as well, alternatly put the jars in the ears lib directory for some app servers (jboss 5+ should support this).

                • 5. Re: JSF component bindings and EAR classloader
                  Israel Fonseca Apprentice

                  To solve that i'm using all the libs in the /lib directory of the EAR. And btw how can i force jboss4.2.3 to use a newer jsf-lib version? I tried to put it on the ear/lib and the ear/war/lib and they did not work (even with the web.xml configuration).

                  • 6. Re: JSF component bindings and EAR classloader
                    H G Newbie

                    I appreciate yours help.


                    I put the richfaces-ui.jar and richfaces-impl.jar  to  jboss-5.1.0.GA-server-default-lib, and build successful the project.


                    This is not the optimum solution but for now I will work with this(In other phase of the project I will have to take this issue again), I hope that the seam team include in future more documentation and universal solution.



                    After build and deploy y try to open the facelet an see the generated menu, but received the next:



                    SEVERE [viewhandler] Error Rendering View[/some.xhtml]<br>
                    javax.faces.FacesException: javax.el.ELException: /some.xhtml @19,64<br>
                    binding="#{mcdevice.mcmenu}": Error reading 'mcmenu' on type<br>
                    org.domain.app.session.MCDevice_$$_javassist_seam_2



                    (I change the name of the seam component and property name, thinking that menu can be reserved word)


                    Is this exception cused by storing richfaces jars to server lib?


                    This is a similar problem

                    • 7. Re: JSF component bindings and EAR classloader
                      Stuart Douglas Master

                      You are going to have to post the full stacktrace, including the Caused By parts.


                      In jboss 5.1 you can put the richfaces libs in ear/lib or in the root of the ear and add entries for them in application.xml.

                      • 8. Re: JSF component bindings and EAR classloader
                        H G Newbie

                        Ok here we go:




                        19:10:27,156 INFO  [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221053)] Started in 5m:35s:235ms
                        19:10:58,390 SEVERE [viewhandler] Error Rendering View[/ttt.xhtml]
                        javax.faces.FacesException: javax.el.ELException: /ttt.xhtml @19,64 binding="#{mcdevice.mcmenu}": Error reading 'mcmenu' on type org.domain.app.session.MCDevice_$$_javassist_seam_2
                             at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:257)
                             at org.jboss.seam.jsf.SeamApplication.createComponent(SeamApplication.java:394)
                             at com.sun.facelets.tag.jsf.ComponentHandler.createComponent(ComponentHandler.java:224)
                             at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:139)
                             at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
                             at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
                             at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
                             at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
                             at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
                             at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
                             at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
                             at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)
                             at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
                             at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                             at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                             at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
                             at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                             at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
                             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.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                             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:178)
                             at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                             at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                             at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                             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:60)
                             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                             at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                             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:235)
                             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                             at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                             at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                             at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                             at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                             at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                             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:158)
                             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                             at java.lang.Thread.run(Thread.java:595)
                        Caused by: javax.el.ELException: /ttt.xhtml @19,64 binding="#{mcdevice.mcmenu}": Error reading 'mcmenu' on type org.domain.app.session.MCDevice_$$_javassist_seam_2
                             at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
                             at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:246)
                             ... 61 more
                        Caused by: java.lang.reflect.InvocationTargetException
                             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                             at java.lang.reflect.Method.invoke(Method.java:585)
                             at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                             at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                             at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                             at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                             at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                             at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                             at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                             at org.domain.app.session.MCDevice_$$_javassist_seam_2.getMcmenu(MCDevice_$$_javassist_seam_2.java)
                             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                             at java.lang.reflect.Method.invoke(Method.java:585)
                             at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
                             at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
                             at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
                             at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
                             at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
                             at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                             at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                             ... 62 more
                        Caused by: java.lang.NoClassDefFoundError: org/ajax4jsf/component/AjaxComponent
                             at java.lang.ClassLoader.defineClass1(Native Method)
                             at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
                             at org.jboss.classloader.spi.base.BaseClassLoader.access$200(BaseClassLoader.java:63)
                             at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:572)
                             at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:532)
                             at java.security.AccessController.doPrivileged(Native Method)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:530)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:507)
                             at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:134)
                             at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:131)
                             at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:452)
                             at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:251)
                             at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:150)
                             at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:265)
                             at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1119)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:798)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441)
                             at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                             at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
                             at java.lang.ClassLoader.defineClass1(Native Method)
                             at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
                             at org.jboss.classloader.spi.base.BaseClassLoader.access$200(BaseClassLoader.java:63)
                             at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:572)
                             at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:532)
                             at java.security.AccessController.doPrivileged(Native Method)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:530)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:507)
                             at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:134)
                             at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:131)
                             at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:452)
                             at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:251)
                             at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:150)
                             at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:265)
                             at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1119)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:798)
                             at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441)
                             at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                             at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
                             at org.domain.app.session.MCDevice.getMcmenu(MCDevice.java:50)
                             ... 88 more
                        



                        • 9. Re: JSF component bindings and EAR classloader
                          H G Newbie

                          In jboss 5.1 you can put the richfaces libs in ear/lib or in the root of the ear and add entries for them in application.xml.


                          I don't now how exactly have to configure application.xml. I add at the final two java modules and then put the two richfaces jars to the EarContent -  doesn't compile,
                          tried also move them to the ear root - doesn't compile.


                          Probably is missing another piece of configuration?



                          <?xml version="1.0" encoding="UTF-8"?>
                          <application xmlns="http://java.sun.com/xml/ns/javaee"
                               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/application_5.xsd"
                               version="5"> 
                                  
                               <display-name>drumk-ear</display-name>
                                    
                               <module>
                                    <web> 
                                         <web-uri>drumk.war</web-uri>
                                         <context-root>/drumk</context-root>
                                    </web>
                               </module> 
                          
                               <module>
                                    <ejb>drumk-ejb.jar</ejb>
                               </module>
                          
                               <module>
                                    <ejb>jboss-seam.jar</ejb>
                               </module>
                               
                               
                               <module>
                                    <java>richfaces-ui.jar</java>
                               </module>
                               <module>
                                    <java>richfaces-impl.jar</java>
                               </module>
                          
                          </application>