• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is the diff b/w the actionform and dto

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic