5 Replies Latest reply on Jun 23, 2006 6:18 PM by Mike Slyter

    Using EJB and JSF: can they communicate?

    None None Master


      I am trying to make a simple "Hello World" JSF + EJB3 application. I have gotten my JSF side working fine. I have gotten some EJBs. But somehow the JSF side can never find any beans. Is it possible to do this? From what I have read people have been able to access beans from within Servlets, and JSF works in the same system as a servlet so it seems like it should be possible... but for some reason it isn't finding it.

      On my bean, I have:

      package entities;
      import javax.ejb.*;
      import javax.persistence.*;
      public class Status implements StatusLocal {
       public int getId() { return id; }
       public void setId(int id) { this.id = id; }
       private int id;
       public String getName() { return name; }
       public void setName(String s) { this.name = s; }
       private String name = null;
       public String getStatus() {
       return status;
       private String status = "This is the status!";
       public void setStatus(String s) { this.status = "My bean says: " + s; }

      I also have:

      package entities;
      public interface StatusLocal {
       public String getStatus();
       public void setStatus(String s);
       public String getName();
       public void setName(String s);

      Then on the JSF side I have a Manager:
      package webside;
      import javax.annotation.EJB;
      import entities.Status;
      public class Managed {
       @EJB() Status status;
       public String getGreeting () {
       if(status == null) return "Oh no the status was null!";
       return status.getStatus();
       public Managed() {

      I can use this within my JSF page, and every time I try to getGreeting, I get "Oh no the status was null". So it isn't even finding the bean at all. Is there a way to do this?

      JSF seems like it would be an excellent companion to EJB! And they are both within JBoss. But if they can't send data back and forth they don't help!


        • 1. Re: Using EJB and JSF: can they communicate?
          None None Master

          And a follow-up question: Actually, at this point it seems like beans can't even be used within plain old servlets. Can someone confirm that I can locate resources using JNDI's InitialContext within JBoss? Is this the right way to find resources?

          I am totally lost on this. It seems like a huge amount of effort has gone into creating J2EE but the different sides have no "glue" that lets them communicate.

          • 2. Re: Using EJB and JSF: can they communicate?
            None None Master

            And a final question: Is JBoss being used? From everything I read about it, it is designed to manage information in databases and expose it to clients of various types (web interfaces, Swing applications, etc). But it doesn't seem like there is any way for a front-end component (like a JSP) to ever find any of the EJBs. I can spend a month working on business logic but if it is never visible to the outside world... I'm not sure how to make use of it.

            • 3. Re: Using EJB and JSF: can they communicate?
              None None Master

              Ok, this is insane. I have spend the last week reading about JBoss and people using it for websites... surely there is some way for view components (JSPs) to display data from the model (EJBs)? Or does everyone have to write his own interface / naming system to do this? If J2EE / JBoss don't have some system to allow communication it would be easier to just use plain old Servlets / JSPs the old way, right?

              I looked at the customers section of the JBoss site and it looks like many large companies are using it, I just can't figure out what it is for or how they are using it. Does anyone know?

              • 5. Re: Using EJB and JSF: can they communicate?
                Mike Slyter Newbie

                Look at the EJB3 trailblazer. That is where I got my start using EJB3. It is a very simple lookup on a bean but I would not directly call my bean from a JSF page. I would have a managed bean communicate with a session facade.

                Here is a basic lookup:

                remoteInterfaceReference = (RemoteInterface) ctx.lookup("ImplementationClass/remote");

                I get a reference to the remote interface for the component I am going to make calls on.