aspose file tools*
The moose likes Struts and the fly likes Using Helper class or a Interceptor for calling EJB from a Action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using Helper class or a Interceptor for calling EJB from a Action class " Watch "Using Helper class or a Interceptor for calling EJB from a Action class " New topic
Author

Using Helper class or a Interceptor for calling EJB from a Action class

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528

This question is in extension to http://www.coderanch.com/t/320398/EJB-Other-Java-EE-Technologies/java/Integration-struts-x-with-Ejb

Jeanne Boyarsky ,

AS you said "have a helper layer that does the JNDI lookup" .This would be better .

Now i want to ask

1. Should i write this helper class as a Interceptor and integrate it with Struts 2 Framework ? OR

Do i write a individual class that will be responsible to do this operation ??

What approach will be better .

Waiting for your response .


If you want something you never had do something which you had never done
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Since this question deals with best practices for Struts 2 interceptors, I'm moving it to our Struts forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Using Helper class or a Interceptor for calling EJB from a Action class