• 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

Struts & EJB - how to mix?

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have an architectural sort of question about how best to mix Struts & EJB. I am building an application in which I am using a Struts-like framework to handle the view and controller (i.e. I use beans to handle form processing and actions to control the flow), and I am using CMP EJBs to handle database access.
As I said, I'm using beans to populate HTML forms with information from the database, but now I'm wondering about how best to populate the beans themselves. Is there a better way of doing it than simply using an action or something to get the fields from my EJB session bean and set their complimentary fields in the form bean? What about using the form bean as a "facade" for my Session EJB (which is in turn a facade for my Entity EJB)? The idea here would be that each get method in my form bean would simply call its complimentary get method in my session bean. Conversely, after validation, each set method would call its accompanying set method in the session bean.
Does this make sense, or would it have some kind of performance cost or other gotcha?
Thanks,
Buzz
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Refer to Kyle Brown's article on Session Facade.
My 2 cents (take this with a grain of salt because I'm no expert ):
1. Using a Session facade in your Servlet ties it directly to the J2EE layer. I would put another layer such as a BrokerInterface layer between my servlet and the actual persistence mechanism. This will make it easier to switch between persistence mechanisms, e.g. if you want to use XML to test, MS-SQL Server to integrate, Oracle or DB2 for production. You won't have to have different versions/methods of the Servlet to handle different persistence layers, you'll just program to an interface in the Servlet and switch persistence layers.
2. Using the Session facade the way you propose (delegate gets) gains you nothing. The session facade should simplify the interface to the entity, not just serve as a pass-through. Use a Value Object (aka Data Transfer Object) as a parameter to the Session Facade. I.e.:
ActionForm <--> Data Transfer Object <--> BrokerInterface <--> Session Facade <--> Entity Bean
It may seem like a roundabout way but it is a more flexible design, IMHO.
Junilu
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm with Junilu (gee, he sure sounds like an expert ). Using a large-grained session facade and data transfer objects is the way to go.
You might want to look at my article on Struts where I talk about similar things. In particular, look at the perform() method in my Action class in the article.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
[This message has been edited by Kyle Brown (edited November 08, 2001).]
[This message has been edited by Kyle Brown (edited November 08, 2001).]
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kyle Brown:
I'm with Junilu (gee, he sure sounds like an expert ).


Aww shucks... Thanks, Kyle. I'm really just regurgitating my understanding of the stuff you and others wrote in articles on VADD
Junilu

[This message has been edited by JUNILU LACAR (edited November 09, 2001).]
 
Buzz Andersen
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to everyone!. Actually, it just so happened that I stumbled onto Kyle's article when I was perusing his website yesterday, and I immediately latched onto his ideas as relevant to my own question. Per the article's recommendations, I have implemented a session facade which provides "large grain" functionality (this actually makes a lot of sense for me since I have to pull data from a lot of different tables/entity beans!) and used JavaBeans as "value objects" to communicate between application layers.
I have to admit I really dig this approach--it results in that nice, clean MVC separation I was looking for. Everything I need in my JSP can be accomplished with useBean and get and setProperty tags, which is very cool!
Junilu, thanks for your advice as well--that seems like sound practice. I will now implement a BrokerInterface layer as well...
Thanks again!
Buzz
[This message has been edited by Buzz Andersen (edited November 09, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic