9 Replies Latest reply on Jan 14, 2015 9:43 AM by mkouba

    @named bean methods not called from EL

    nandagopal1987

      Hi

       

      I am using jboss-as-7.1.1.Final as the server for my application which consists of a war and several jar modules.

      I had some beans in my jar modules with the @Named annotation and I was able to access these beans directly from EL from my war module.

       

      I upgraded my weld version from weld-core-1.1.5.AS71.Final to weld-core-1.1.26.Final and found that the EL expressions (from war) are not invoking the functions present in the @Named bean in the jar.

      Everything works as expected when I have the @Named bean in the war and i call it from EL!! 

       

      Is this a bug or are we not supposed to have @Named beans in other jars ?

      Or have i just made some configuration mistake?

       

      P.s

      • I do have a beans.xml in the META-INF folder in my jars
      • I have seen the logs and there are no errors or warnings !
        • 1. Re: @named bean methods not called from EL
          jharting

          Hi Nandagopal,

           

          JBoss AS 7.1.1 is pretty old. I suggest that you upgrade to WildFly 8.

          • 2. Re: @named bean methods not called from EL
            nandagopal1987

            Thanks for the swift reply.

            I understand that JBoss AS 7.1.1 is pretty old. I just want to understand the specification better.

            So it should always be possible in an application to call a method from a @named bean from a jar via EL from a war.

            Am i correct?

            • 3. Re: @named bean methods not called from EL
              mkouba

              Hi Nandagopal,

              the @Named bean must be visible from the WAR. What's the structure of your application?

              • 4. Re: @named bean methods not called from EL
                nandagopal1987

                I hope you mean the deployment structure as in jboss-deployment-structure.xml !

                 

                <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

                    <deployment ear-subdeployments-isolated="false">

                        <dependencies>

                            <module name="javax.faces.api" export="true" />

                            <module name="org.apache.log4j" export="true" />

                            <module name="org.dom4j" export="true" />

                            <module name="org.apache.commons.logging" export="true" />

                            <module name="org.apache.commons.collections" export="true" />

                            <module name="org.apache.commons.configuration" export="true" />

                            <module name="org.apache.xerces" export="true" />

                            <module name="org.apache.xalan" export="true" />

                            <module name="org.apache.commons.digester" export="true" />

                            <module name="org.apache.httpcomponents" export="true" />

                        </dependencies>

                    </deployment>

                    <sub-deployment name="J2EE-BillingDocumentWeb.war">

                        <dependencies>

                            <module name="org.richfaces" slot="4.3.1.Final" >

                                <imports>

                                    <include path="**"/>

                                </imports>

                            </module>

                        </dependencies>   

                    </sub-deployment>

                </jboss-deployment-structure>

                • 5. Re: @named bean methods not called from EL
                  mkouba

                  No, I mean whether it's an EAR or a WAR, what and where are you modules (e.g. an EJB module or a shared lib in WEB-INF/lib), etc. I'm sorry for not being more specific.

                  • 6. Re: @named bean methods not called from EL
                    nandagopal1987

                    It is a WAR and all my modules are EJB modules

                     

                    Something like this

                    <?xml version="1.0" encoding="UTF-8"?>

                    <application    xmlns="http://java.sun.com/xml/ns/javaee"

                                    version="6"

                                    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_6.xsd">

                       

                        <module>       

                            <ejb>Module1.jar</ejb>

                        </module>

                        <module>

                            <ejb>Module2.jar</ejb>

                        </module>

                          <module>

                            <web>

                                  <web-uri>J2EE-BillingDocumentWeb.war</web-uri>

                                  <context-root>BillingDocument</context-root>

                            </web>

                          </module>

                    </application>

                    • 7. Re: @named bean methods not called from EL
                      mkouba

                      So your application is packaged as an EAR, an EL expression is declared in a WAR module and @Named bean is packaged in an EJB module. By default, WARs don't see the classes from EJB modules. You must have ear-subdeployments-isolated set to false (default, non-portable) or have a Class-Path entry in the MANIFEST.MF of the WAR (portable). See also https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7#ClassLoadinginAS7-EARClassLoading.

                      1 of 1 people found this helpful
                      • 8. Re: @named bean methods not called from EL
                        nandagopal1987

                        Thanks a lot for the quick reply .

                        Yes i do have the ear-subdeployments-isolated set to false, it was working previously as expected ( weld-core-1.1.5.AS71.Final).

                        It stopped working after I upgraded my weld version (weld-core-1.1.26.Final)

                         

                        I don't understand why it should stop working! I guess there is no solution for this other than upgrading by application server ! or is there ?

                         

                        I was confused because i was not sure whether it was technically allowed and correct to have @Named beans packaged in an EJB module.

                        Is it bad practice or is it perfectly normal ?

                        • 9. Re: @named bean methods not called from EL
                          mkouba

                          It seems that WELD-1589 is related. However, it's only fixed in the JBoss EAP codebase. So you could either switch to Red Hat JBoss Enterprise Application Platform (supported version of AS7, has a free developer version) or upgrade to WildFly.

                          I was confused because i was not sure whether it was technically allowed and correct to have @Named beans packaged in an EJB module.

                          Is it bad practice or is it perfectly normal ?

                          I would say it's not a good idea but it should work.