-->
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: best practice of passing selective properties to view layer
PostPosted: Thu Jan 26, 2006 3:18 am 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
Hi,
Would like to seek advice: what's the common way of passing selective properties back to the view layer?

In the past I always pass back a list of full objects but recently I need to pass some selected properties only back to view layer (JSP). Passing back the full object makes the view layer processing much easier because in JSP I can access the individual property by referening it name. But passing back selected properties will loss this advantegy:

the selected properties of each matched object are put into array object [], the view layer can only access the properties using an index number. This looks like hard coding something in two places: one in the DAO layer (determine what to return) and one in View (JSP) which must have the knowledge of which properties fetched and their sequence as well.

Another way is to put the selected properties into a new Class in my service manager (by using an intermediate class to keep the selected proerties so JSP can still access the properties by using names), but I am afraid that this will have some performance impact especially when the result set is big enough.

So what's the common practice for this problem ?

thanks
lixin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 4:54 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
I wonder why you want to only pass selected properties? - I'd have thought that the whole object would be better, but obviously there must be a reason.

What I would do is create a separate lightweight class (The terminology for which is a Data Transfer Object) and then do a copy into it from the hibernate model object. This way you still have some good control over what is passed accross - using arrays is a messy solution in my opinion and will lead to uncertainties and errors.
The commons beanutils project may have by the way as if you keep the same name of the properties in both classes you can do a
Code:
  BeanUtils.copyProperties(hibernateModelObject, dtoObject);

As a performance hit, yes there is one, but it is very small - and it is common in my experience to do a copy the other way from (say) a strutsForm to a model obejct in the action to pass the stuff back to the back end so it is used in practice.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 9:59 am 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
thanks for your help.

here is my use case:
a program can have any number of members. I have a 'members' property in the program. the 'members' is a list of composite-element, which keeps: which user, what role (member, owner, etc), and role status (pending, approved, rejected, etc).

A user may want to get a list of programs that he is a member of. I would like to display a list of such info:

program name, role, role status

If I return a list of programs, then the Struts Action or JSP has to filter out the members and shows the requester's member status only. I thought it would be nicer if I do not return all the members but only the requester.

This is the main reason. Currently I return a list of object [] with selected program's and the member's info for the requester. I agree with you that I need to pay for the cost of maintenance.

If the cost of instantiate a class is minimum, then I will return a DTO with two properties: program and member (which is the requester's membership information)

thanks again
lixin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 5:16 pm 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
No chance you can just model it as a biderectional many-to-many where the programs have a set of users, and the users a set of programs? That way where you get the user, and call getPrograms(), you will only get it's programs? Sounds like you have a unidirectional association where you need bidirectional.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 7:45 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
agree with you. it is indeed a ternary relationship. I was using a seperate class with (user, program, role, role status) to handle this. but after reviewing all use cases, i moved the membership (user, role, role status) into the Program class. I was hoping that it can simplify a lot other user cases/operations.

I will do more study on this case and may try DTO as well to see if it is a good approach also.

thank you very much for your advice !
lixin


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.