Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB usage ... some basic knowledge gathering  RSS feed

 
T Masga
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to better understand EJB3, and I need some info to sort some basic thoughts on my head.

I'm constructing a simple Statefull EJB with JSF as user interface.

It's a simple CalculatorBean that has a value property and some methods:
- operation (like add)
- getValue (returns the value property)

So On my jsf managed bean I'm accessing it remotely, like:



Still I need some knowledge glue to sort my thoughts out and continue working on this example:

1# If I'm accessing an EJB bean that is on the same machine, I should use the local interface right? So I would just inject "private CalculatorRemote calculator;" right?

2# Also, how does it work in JSF? I mean, first time I access the managed bean, it will instantiate the ejb instance and inject it, so I can use it safely ... but then the response is sent back to the user ... if the user fills a text field with a value to add, then clicks an add button, it will go to the managed bean again ... but won't it create a new instance and inject it again, loosing the previous state?

3# Another question, should I use my beans through local interface, if they (webapp and ejb) are packed in the same ear? Then, if one day I install the ejb package on a remote server, I have to re-engineer my app code to instance remote interfaces, am I right? If this is true, then what should be the best practice, to use remote calls from the start?


Thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36396
453
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T Masga wrote:1# If I'm accessing an EJB bean that is on the same machine, I should use the local interface right? So I would just inject "private CalculatorRemote calculator;" right?

Yes, you should use a local interface if in the same ear. Calculator is not the local interface though.

T Masga wrote:2# Also, how does it work in JSF? I mean, first time I access the managed bean, it will instantiate the ejb instance and inject it, so I can use it safely ... but then the response is sent back to the user ... if the user fills a text field with a value to add, then clicks an add button, it will go to the managed bean again ... but won't it create a new instance and inject it again, loosing the previous state?

Web applications should use stateless session beans. The state should be stored in the web layer's HttpSession. If you are using a stateless bean, it doesn't matter if you use a different instance.

T Masga wrote:3# Another question, should I use my beans through local interface, if they (webapp and ejb) are packed in the same ear? Then, if one day I install the ejb package on a remote server, I have to re-engineer my app code to instance remote interfaces, am I right? If this is true, then what should be the best practice, to use remote calls from the start?

Unless you specifically expect this to change, use local. You will have to change the ear anyway to make a remote call; it isn't a seamless change.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!