-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Data passing among layers
PostPosted: Mon Apr 25, 2005 4:31 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
Hi All,

I have an Architectural question. I am using Hibernate 2.1 and Middlegen. I need to pass the data user enters in Struts DynaForm to the backend, also the data collected from Hibernate/Data layer back to the front end. At present we are asking web developers to populate POJO (which at times get complex due to other children relationships) and pass it as a parameter to the backend. In this process web developers are getting exposed to the databse structure and the business rules in order to populate POJO correctly. I would like to avoid this exposure so the front end developers need not worry about the details.

The same problem comes in the return trip too. How to pass information back to the front end so they can display it. If it is a simple POJO structure, it is usually not a problem, but in complex parent child relationships it becomes quite a bit work for front end.

I was wondering how you guys have tackled this problem in your project ?

My goals:
1. To make life easy of front end developers so that they need not know back end complexity.
2. To avoid front end layer dependency on the back end.

Thanks in advance.

Ron


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 4:48 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
You're not going to be able to get around some kind of mapping. Either the backend has to know what the front end looks like or vice-versa. In my experience, the back end changes less frequently than the front end, so it makes sense for the front-end developers to perform the mapping.

That being said, you can create a helper class that takes a DynaActionForm (or simply a Map with name-value pairs) with some predictable set of keys and maps them onto a set of POJOs. Once that mapping helper is done it can be re-used when appropriate, and if changes are necessary they only need to be done in one place.

If you want to get really sophisticated, you can create an XML mapping document that maps named keys to property names and use that to drive the mapping helper. That way you could (potentially) change the mapping behavior without changing code. For example, suppose a developer adds a property to a struts <form> element (configuration), adds a field to a JSP (might as well be configuration), and then adds a mapping to the XML document (configuration), which accomplishes the change without bothering the back end folks.

But then you have configurations to deal with...on top of web.xml, struts-config.xml, and your Hibernate mapping files. It really depends on the size of the project and the required flexibility as to whether it would be worth it. Personally, I would start with a plain old Java helper class to do the mapping and expand on that as needed (i.e. establish the API and then change the implementation later if necessary).

Hope that helps,

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 3:20 am 
Beginner
Beginner

Joined: Wed Apr 21, 2004 8:33 am
Posts: 27
Hi Typically in our web-applications we do the following :

We have a model-java-beans replica of your front end. Each dyna form will be associated with that particular model. You can pass this model to your service layer then instantiate the value objects transfer the data from model to value object and then using this value object do the necessary transaction in your DAO layer (Hibernate save or update). Similary while retreiving also you retreive the valueobject and instaite the model and associate the valueobject to the model. Thereby you can have only your front end details in the model which may or may not be an exact replica of your value object.
Thereby front end knows only about the models since you are exposing only the model or the java-beans in your jsp. As and when your model grows or value object grows you can just change the service layer where the data transfer is done.

Hope my explanation makes sense

Thanks
Yenne


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:34 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
If I understand correctly, you will have a model java bean which carries the screen values. It most cases it may end up a replica of POJO thus two similar objects in the system ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 7:42 am 
Beginner
Beginner

Joined: Wed Apr 21, 2004 8:33 am
Posts: 27
yeah in most cases it will be a replica of your pojo's , however it allows you to have a neat separation between your front-end and back-end. Also if you are doing server side validation you can pass this model and valiadate , also you can add hidden variables if any in yoour front end which might want to carry over to further layers based on that you might decide should your variable in your bean really transfered to POJO. howver its an over design, But you can be sure ur front end is replica of ur model , and POJO is replica of your back-end

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.