Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access one bean from another

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got 2 beans that don't know about each other (and I do not believe they are EJBs). I need one to access an attribute of another, and I'm thinking there's a way to get ahold of the SessionContext and use that to access the other bean and eventually get a value stored in that bean. I know that when I'm in a servlet's doPost method, I can call something like this:

So when I'm in another bean and don't have access to that HttpServletRequest object, how can I get ahold of that UserAcctBean? Or how can I get ahold of the session? Or do I get ahold of a SessionContext and do something with that?
Thanks!
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted a link to this message in the servlet forum in case more readers there would know the answer to this.
 
Ankur Srivastava
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is an entity bean then it would have been very easy. You can get the refference to the remote object using a context lookup and access any field of that Entity Bean but as you mention that you beans are not EJBs then probably this approach should work.
Extend the one bean class by another ans set the scope of bean where ever you are refferencing it as session.
 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heya,
I am not sure I understand you issue, nut here is a typical remote client code to access an EJB :
Context context = new InitialContext();
BeanHome home = (BeanHome)javax.rmi.PortableRemoteObject.narrow(context.lookup(BEAN_JNDI_NAME_FOR_HOME),BeanHome.class);
BeanComponent_Interface bean = home.creat<METHOD>(...);
int x = bean .method_cal(); // method call
Hope this, helps,
Cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic