File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes what is the diff b/w the actionform and dto Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "what is the diff b/w the actionform and dto" Watch "what is the diff b/w the actionform and dto" New topic

what is the diff b/w the actionform and dto

thayakotli krishna

Joined: Nov 20, 2007
Posts: 2
Hello, can anybody tell me the what is the diff b/w actionform and dto,

If we are working with struts we have been available with the actionform that is just like a simple java bean as dto, even though we use the dto and populate the properties into it from the actionform. Instead again creating the dto object and populating the data from the actionform we can directly send the actionform then what is the main diff b/w these two.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Since you mention ActionForm, I have to assume you are talking about Struts 1.x. The trend in the past few years as been toward non-intrusive frameworks and POJO programming (Plain Ole Java Objects). Struts is from a different period at it is intrusive and it does not really support POJO programming. Your form and action need to extend ActionForm and Action (or one of their derived classes). It would be a bad idea to have DTOs that are used in your business and data layers extend a Struts class.

Another difference is in how Struts works with editable fields such as numbers and dates. These properties really need to be Strings in your form but they are likely something else in your DTO (Date, Double, etc.). I also find that the form class is a good place to stick simple presentation layer logic. For example, maybe your DTO has fields for Address 1, Address 2, City, State and Zip but you need to display these as one value in your page. I would much rather implement this logic in Java than in a JSP so I add a getFullAddress method to my form and put the logic there.

Having to write code to translate between DTOs and forms is a bit of a pain, but it is straight forward code and I don't really see a good way to avoid this with Struts 1.x. With Struts 2 it seems possible to have your Action class contain a DTO and interact directly with the DTO, but I have not done enough with Struts 2 to know what the best practices are.

- Brent
I agree. Here's the link:
subject: what is the diff b/w the actionform and dto
It's not a secret anymore!