When I 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:

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)

Of course, you can download the entire project (that has these examples in
it) at http://raibledesigns.com/wiki/Wiki.jsp?page=AppFuse.

HTH,

Matt

-----Original Message-----
From: Blake Whitmore [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 18, 2003 9:55 AM
To: Struts Users Mailing List
Subject: RE: Making Value Objects Into Form Objects


Hey Alan,

It seems to be a pretty popular mechanism out there.
Anyone else have any other ideas? And Alan, dig deeper
into the API - it does more conversions than you think
:)  

For a while I had protected (my form would be in the
same package as my action) 'convienence methods' for
converting between value objects and actionforms. 
Later I went to using another layer of indirection
with a separate class.  But, using the BeanUtils has
made my life easier.  Be careful with 'Date' things
though.  Good luck.

-Blake

--- "Weissman, Alan" <[EMAIL PROTECTED]> wrote:
> Thanks Blake!
> This doesn't seem as comprehensive a tool or design
> pattern as I would have
> liked.  Is this what everyone is using?  It seems
> like a lot of work,
> especially because it doesn't do data type
> conversions for you!
> Alan
> 
> -----Original Message-----
> From: Blake Whitmore
> [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, June 18, 2003 11:14 AM
> To: Struts Users Mailing List
> Subject: Re: Making Value Objects Into Form Objects
> 
> 
> Alan,
> 
> A good tool for this is the
>
org.apache.commons.beanutils.BeanUtils.copyProperties()
> method.
> 
>
http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils
> /BeanUtils.html
> 
> 
> 
> 
> --- "Weissman, Alan" <[EMAIL PROTECTED]> wrote:
> > 
> > Ok so I'm a little new to Struts but not J2EE and
> > I've been noticing that my
> > Value Objects that come out of EJB's in my data
> > layer are the exact same
> > objects as the ActionForms that are used by
> > Struts....and I'm sure I'm not
> > the first to notice this.
> > 
> > So here's my question:  How can I make one class
> > that can serve as both an
> > ActionForm and a ValueObject?  
> > 
> > The problems with solutions that I've brainstormed
> > are this:
> > 
> > 1) I can't make my Value Objects extend ActionForm
> > for obvious reasons.
> > 2) I would rather not use an interface to get
> around
> > this issue because then
> > I have two classes to maintain again.
> > 
> > Thanks for any advice!
> > 
> > Alan
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > 
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to