my dog learned polymorphism*
The moose likes Struts and the fly likes DTO and ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DTO and ActionForm" Watch "DTO and ActionForm" New topic
Author

DTO and ActionForm

Kris Bal
Greenhorn

Joined: Dec 24, 2006
Posts: 19
In my application which uses Struts,
I have some Data Transfer Objects(DTOs) which are all complex DTOs (ie it contains some objects also).

what I populate in the ActionForm is all strings input from the user.How to populate the DTOs from the ActionForms.
I think i cannot use BeanUtils.copyProperties(actionForm,dto) directly to copy the properties from my action form to DTO as the DTO contains some objects also.(These objects inside DTO has to be built from the data input by the user).

How to achieve this?

Also in the reverse,when displaying the details to user how to copy the properties from the DTO to action form?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I write this code manually and put the methods in my action form. It is a bit of a pain but it works.

- Brent
H Ritwick
Greenhorn

Joined: Mar 15, 2006
Posts: 18
For BeanUtils copy to handle non registered converters, you can write custom converters. This had worked for most of the cases for me. But still after bean utils copy, I was also doing few explicit object creations and setting them to dto.

http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/converters/package-summary.html

http://www.javaranch.com/journal/200406/BeanUtilsDigesterAndTypeConversion.html
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DTO and ActionForm
 
Similar Threads
A buildDTO() in Action or in ActionForm ???
How to determine when a form field is submitted if it's changed from the original value?
what is the diff b/w the actionform and dto
Advice on persisting complex state across multiple server trips
Do I need to implement Serializable inteface.