Forums Register Login

Struts & EJB - how to mix?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
 

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).]
+Pie Number of slices to send: Send
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).]
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 981 times.
Similar Threads
Moving a bean from request to session context
Spring security: pass additional parameter when performing login
Ejb Project Plan
PartII - EJBController vs. Business Delegate
How to access CMR-fields in SessionBeans
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:35:36.