The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20121014

jboss 4.2.2.GA how to get ejb3 stateless session bean using jndi in jsf 1.2 managed backing bean

##########
// JSF 1.2 backing bean

@org.ajax4jsf.model.KeepAlive
public class TripManagerBean {
  private TripLocal tripBean;
  public TripManagerBean() {
...
    initTripBean();
  }

  private void initTripBean() {
    if(tripBean == null) {
      try {
        tripBean = (TripLocal) InitialContext.doLookup("earName/TripBean/local");
      } catch (NamingException e) {
        e.printStackTrace();
      }          
    }
  }
...
}
##########

earName is foo if the EAR is called foo.ear.

##########
// EJB3 bean

@Stateless
public class TripBean implements TripLocal {
  @PersistenceContext
  private EntityManager em;
...
}
##########

##########
// EJB3 bean local interface

public interface TripLocal {
...
}
##########

thanks to this page about jndi bindings in ejb3

and here's how to inject an ejb3 stateless session bean into a jsf managed backing bean using the ejb annotation

No comments:

Post a Comment