• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use EJB with Struts????

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created Successfully EJB Beans for my Application. Now for my web application I want to insert record into database. Where should I write lookup code for bean? Currently I am writing it in Action file inside execute method. Is it right way to do that? If not then waht is the best way to use EJB's with struts?

Please tell me.

Thanx in advance.

Prash
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i am not sure about this approach. What i was doing in one of my project is i use a Helper class which in turn have the ejb lookup part and other implementation part. So only this class call used be there in my action class.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I worked on one major Struts/EJB project where we did that...performed the JNDI lookup in the action code. It works. We used a utility class where you passed in the name of the ejb home. The downside to this approach is that your "web" tier is now dealing with EJB specific tasks and exceptions (as long as you count your Action classes to be part of your web tier).

The project that I have been on for the past few years uses a "Business Delegate" pattern to isolate the web tier from the business tier. This delegate primarily handles JNDI lookup and exception translation (translating EJB specific exceptions into generic project exceptions). After coding dozens of these delegates by hand (they are pretty boring...they mostly just pass through parameters) one of the developers rolled out a dynamic delegate. It uses reflection and an interface that your EJB implements. It introduces some runtime overhead, but saves us from having to hand code delegate code. I am pretty sure his code was based of something pulled off the Internet.

I am sure if you search the web for "Business Delegate" or "Dynamic Delegate" you will find more info.

- Brent
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..

Brent's approach is absolutely fine. Use a Business Deligate class which is nothing but a plane java class (POJO approach) which takes care of all EJB specific tasks. However, don't put your JNDI lookups into deligate class. Rather use Service Locator pattern to do that. A Service Locator is again a java class which may contain methods (say) like , which may do all the JNDI lookups for an EJB (say) CustomerManagerEJB and keeps that remote reference in a Hashtable so that next time you require the same reference, you can get it from the Hashtable. Just search in SUN's web site for Service Locator pattern. And with the help of Business Deligate and Service Locator patterns you can isolate your business layer from web layer. And your struts action class or other servlets may call methods on Business Deligate class only.

Hope this helps.

Regards,
Niranjan
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i think the best approach is to use the struts as controller ,just. and if you deal with the database, use JDO or DAO in the execute method to call the business (ejb) which in turn call the database...
to make the best approach use the javaserverfaces as view...so you implemented the the pure MVC design pattern.....
please if there is better approach tell me ..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic