Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Mojavelinux
POJOsToForms
ValueObjectInForm




JSPWiki v2.2.33

[RSS]


Hide Menu

DTOInForm


Difference between current version and current version:

At line 1 added 32 lines.
This is really a hot topic right now in Raible world and I would very much like to determine how best to use this design in applications. In short, what relationship do DTO objects and ActionForms (or DynaActionForms) have and where are the supporting methods for these objects added. That is the question on the table.
!!The history of appfuse's DTO/ActionForm design
When [I|MattRaible] first started developing with Struts (pre 1.0), I'd just have a simple form with a DTO (VO back then) as a getter/setter on my form. In the last year, I've changed to have a DTO and a Form, where the DTO has the true data types (Long, Date, etc) and the form has only Strings. After doing it both ways, it seems like the DTO as a getter/setter is really the better way
to go. I'm not trying to say it's the *right* way according to the design patterns, I'm just offering my $.02 from experience. I continue to do it the BeanUtils.copyProperties() way, but the projects I work on that do it the other way seem cleaner.
For an example of a DTO -> BeanUtils.copyProperties() -> Form, check out the following links:
<div style="background: #eee; padding: 5px; border: 1px solid silver">
DTO -> User.java (source: [http://tinyurl.com/emo7])
Conversion -> UserManagerImpl.java (source: [http://tinyurl.com/emof]
- see convert() method). This extends BaseManager ([http://tinyurl.com/emok]),
which registers custom converters. No DateConverter in this example,
but I've done it at my day job, so I know it's fairly easy.
Form -> UserForm.java (generated via XDoclet from User.java)
</div>
''This discussion originated on the [struts-user mailing list|http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg69836.html].''
~ [MattRaible]
__Related Pages:__
* [POJOsToForms]
__Comments:__
----
So if this is not the *right* way, what would the *right* way be, just so that we know what to compare it with? Say I wanted to have a method on the User object called getFullName(), maybe as a convenience method for my jsp developer. Where would I put that? Let's also talk about Dates, since everyone always says that that can be handled but never shows examples. Also, what about sub-forms. Say for instance the user has an address and in the form we need to access that address. How would we do it? I think answering these questions will really clear up a huge gap a lot of Struts developers have when blueprinting their app.
~ [mojavelinux]

Back to DTOInForm, or to the Page History.