5 Replies Latest reply on Dec 13, 2007 9:48 AM by je.a.le

    How to access EJB3 beans from a portlet !???

    stefnef

      Hi all.

      We have an app. on a clustered jboss deployed as an .ear file in the farm folder. It is a webapp backed by JMS + EJB3 beans (local interfaces) and runs fine.

      Now I am messing around with portlets and of course I want to invoke our business code in the EJB3 beans from a portlet.

      Big question is : How do I do that !??

      I tried to deploy the portlet as a .war bundled within the .ear file, but that didn't do any good :-(

      Deploying the portlet as a standalone .war file in the deploy folder works, but how do I then access the EJB3 beans !??

      Cheers,
      Steffen

      System: JBoss 4.2.1.GA + JBoss Portal 2.6.1

        • 1. Re: How to access EJB3 beans from a portlet !???
          stefnef

          I found the solution myself. Bundle the helloworldjspportlet.war inside the .ear file and add this to the application.xml in the META-INF folder :


          helloworldjspportlet.war


          That's it !
          Sorry for the premature post...;-)

          • 2. Re: How to access EJB3 beans from a portlet !???
            stefnef

            Sorry..I am new to these forums ... here should be the missing code lines :

            <module id="HelloWorldJSPPortlet">
             <java>helloworldjspportlet.war</java>
            </module>
            


            If that didn't work then the idea is to add the module as a java module
            in the application.xml file and not a war module !



            • 3. Re: How to access EJB3 beans from a portlet !???

              Hi, I have the same problem you described, have you found a solution?

              Thanks
              Ivan

              • 4. Re: How to access EJB3 beans from a portlet !???
                soon5

                Hy,

                Why don't you use JNDI to get the EJBs and access them?

                Greetings Soon5

                • 5. Re: How to access EJB3 beans from a portlet !???
                  je.a.le

                  in netbeans, right click on editor, "entreprise resources"->call entreprise bean
                  select your ejb, remote/local depending where you add your portlet.

                  netbean add a method to your portlet for you... except the jndi is wrong :-)
                  so too call an ejb "MediaDirSessionBean", from the application project "AC", with local interface, jndi is : "AC/MediaDirSessionBean/local"

                  the full function should look like this one :
                  private MediaDirSessionLocal lookupMediaDirSessionBean() {
                  try {
                  Context c = new InitialContext();
                  return (MediaDirSessionLocal) c.lookup("AC/MediaDirSessionBean/local");
                  } catch (NamingException ne) {
                  java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
                  throw new RuntimeException(ne);
                  }
                  }

                  A+