0 Replies Latest reply on Oct 3, 2012 4:10 PM by faustodelatog

    Reference managed beans in other module

    faustodelatog

      Hi,

       

      I have a portal.war wich contains a few jsf pages and one (ManagedBean) Bean annotated @Named, in this war there is a file  WEB-INF/beans.xml, I can reference managed bean in jsf pages throw EL, everything works fine in this application.

       

      Now, I have a another.war which depends of portal.war, the file another.war/META-INF/MANIFEST.MF contains the dependency (Dependencies: deployment.portal.war) and contains too WEB-INF/beans.xml, in this another.war I have a few jsf pages and a few ManagedBeans (Beans annotated @Named), in jsf pages I can reference managed beans which are in another.war throw EL whitout problems, however I want to reference the portal.war managed bean in my another.war jsf pages but I can not.

       

       

      portal.war

      another.war

      WEB-INF/beans.xmlok

      WEB-INF/beans.xml

      ok

      com.test.portal

       

      @Named public class PortalManagedBean {...

      ok

      META-INF/MANIFEST.MF

         ...

         Dependencies: deployment.portal.war

         ...

      ok


      com.test.another

       

      @Named public class AnotherManagedBean {...

      ok

      portalHome.xhtml

         ...

         <h:outputText value=#{portalManagedBean.text} />

         ...

      ok

      anotherHome.xhtml

         ...

         <h:outputText value=#{anotherManagedBean.text} />

         ...

      ok


      anotherHome.xhtml

         ...

         <h:outputText value=#{portalManagedBean.text} />

         ...

      FAIL

       

       

      Two files portal.war and other.war are deployed in jboss 7.

       

      I have read cdi documentation, I understand that a library or module wich contains a beans.xml is a "bean archive" and beans which are packaged in a bean archive are available for injection, lookup an EL resolution to classes ans jsf pages packaged in some other bean archive. According to what the documentation says textuallyin the chapter of Modularity

       

      " Beans and their clients may be deployed in modules in a module architecture such as the Java EE environment. In a mod-

      ule architecture, certain modules are considered bean archives. In the Java EE module architecture, any Java EE module or

      library is a module. The Java EE module or library is a bean archive if it contains a beans.xml file, as defined in Sec-

      tion 12.1, “Bean archives”.

      A bean packaged in a certain module is available for injection, lookup and EL resolution to classes and JSP/JSF pages

      packaged in some other module if and only if the bean class of the bean is required to be accessible to the other module by

      the class accessibility requirements of the module architecture. In the Java EE module architecture, a bean class is access-

      ible in a module if and only if it is required to be accessible according to the class loading requirements defined by the

      Java EE platform specification.

      Note that, in some Java EE implementations, a bean class might be accessible to some other class even when this is not re-

      quired by the Java EE platform specification. For the purposes of this specification, a class is not considered accessible to

      another class unless accessibility is explicitly required by the Java EE platform specification.

      An alternative is not available for injection, lookup or EL resolution to classes or JSP/JSF pages in a module unless the

      module is a bean archive and the alternative is explicitly selected in that bean archive. An alternative is never available for

      injection, lookup or EL resolution in a module that is not a bean archive."

       

       

      I have found a "solution" for this but I do not believe that is the best way, is for that I want to ask you What I can do for this purpose.

       

      My "solution" is create an empty class com.test.portal.PortalManagedBean in another.war, thus jsf pages can resolve #{portalManagedBean.text}, But i repeat I do not think is the correct way.

       

      PD: My english is not the best, I hope you undestand me