wood burning stoves 2.0*
The moose likes Struts and the fly likes How to suitably use DTO with Struts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to suitably use DTO with Struts?" Watch "How to suitably use DTO with Struts?" New topic
Author

How to suitably use DTO with Struts?

Perry McKenzie
Greenhorn

Joined: Jul 16, 2003
Posts: 23
Does anybody have any suggestions as to where the best place to convert my DTO into an ActionForm and vice versa? I'd like to put all the conversions for all the ActionForms in one class if that makes sense. Right now my conversion methods sit inside my DTO, but that doesn't seem right to me.
I've thought of putting the conversion methods in the ActionForm superclass. It seems to me that there should be a class in our 'domain' layer (for our application that is where the business logic is performed) that should have these 'convertToActionForm(),convertFromActionForm()' methods.
Any suggestions?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I would create a constructor in the FormClass which takes your Transfer object. Cause the DTO don't has to know anything about it, and for me this would be the nicest solution.
But you can also create a super class with a method like
Perry McKenzie
Greenhorn

Joined: Jul 16, 2003
Posts: 23
I like your ideas Oliver, except that the way I see them, they only perform the conversion one way. I would like to use the same type of conversion both ways.
What I mean by this is if I used a constructor in the ActionForm class to convert the DTO to the ActionForm, I can't use a constructor in the DTO (and certainly not the ActionForm) to convert the ActionForm back to the DTO.
Is there a common way that these conversions are done?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
There is nothing to be said against doing the same for your DTO's or not?
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I would recommend putting your conversion methods in their own class, not in the DTO or the ActionForm. They certainly don't belong in the DTO as the DTO should just be your data. Similarly, I wouldn't place them in the ActionForm either.
As far as conversions going both ways, you really only need to write one conversion method, whether or not you are going DTO-to-ActionForm, or ActionForm-to-DTO. Just use the BeanUtils package. See my article Touring the Commons - part 1 in July's newsletter for more info on using the BeanUtils package.
[ August 01, 2003: Message edited by: Jason Menard ]
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
Is a data transfer object (DTO) a data object (DO) or value object (VO)? I always get confused on these issues because people seem to use them interchangeably although DO's or quite different than VO's. I am guessing a DTO is a VO since they are both used to transfer objects between nodes and tiers.
If this is so, I usually situate a collection of delegate classes between the presentation and business tiers and assign it responsibility for creating and transfering objects TO the business tier and for seeding the request object with VO's returned from the business tier. In the business tier itself, I create a session bean whose sole purpose is to assemble VOs to return back to the client tier -- IF bean managed persistence is in place. If container managed persistence and container managed relations are in place, I let the entity beans create their own VOs.
Darryl
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Originally posted by Darryl A. J. Staflund:
Is a data transfer object (DTO) a data object (DO) or value object (VO)?

Value Object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to suitably use DTO with Struts?