This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I haven't done enough "real" work yet with either EJB 3 or Struts 2 to be sure of best practices. That said, I think it would be better to stay with the helper method approach to keep the scope as narrow as possible for the bean.
I look forward to reading replies to this thread to see if I am wrong.
It'd depend on how you want to use the helper class--the two solutions provided aren't mutually exclusive
If you were going to write an interceptor (to move the JNDI lookup out of the action--the interceptor would inject the results of the lookup into the action) you'd use the helper class from the interceptor. Or you can skip the interceptor and put the JNDI lookup in the action itself.
It may depend on how you'll be testing your action: by having the interceptor inject the result into the action you increase action testability in that you can inject whatever you want into the action from a test class regardless of how the "lookup" is actually done. For example, you might inject a stub interface implementation during testing, eliminating the need to set up JNDI lookup just for the test environment.
Joined: Jan 30, 2009
David thanks for your response. I found a open source Guice Struts 2 plug-in for this injection purpose .I decided to use that for temporarily .
Thanks for keeping answering my queries with Struts 2 Framework.