You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Robert Bowen <sy...@yahoo.com> on 2004/08/17 14:28:10 UTC

BeanUtils copProperties with Struts and Torque?

Hello. I am using Torque to generate the persistent
classes for my web application. Torque generates these
classes based on an xml file, in which you specify the
table name, column name and column type.

What I would like to do is use copyProperties() to
copy from an ActionForm directly to my
Torque-generated beans but of course, everything is a
String in the ActionForm world, whereas in my
persistence classes my date fields, for example, are
Dates, not Strings, so copyProperties fails.

I have been looking all over the jakarta web site, the
archives of this mailing list, etc. People seem to be
talking about creating a bean that acts as a
go-between, a DTO I suppose, that has the same fields,
getters and setters as the ActionForm, and that you
first copy the properties to the DTO. 

But ... won't I have the same problem when trying to
use copyProperties? Do I have to somehow use the
ConvertUtils instead?

Any help much appreciated. I am using a single servlet
to instantiate a bean of type 'x', copy the values
from a form and save it in the database, so having to
type 'gets' and 'sets' for every possible case ... is
a waste of time, bad design, etc.

Many thanks!
syg


		
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: BeanUtils copProperties with Struts and Torque?

Posted by Craig McClanahan <cr...@gmail.com>.
The PropertyUtils.copyProperties() method does *not* perform any type
conversions -- it expects the types to match already.  However,
BeanUtils.copyProperties() will apply the appropriate converters that
have been registered in ConvertUtils for you.  That makes it more
useful for copying data to a DTO (which uses native data types) from a
form bean (which typically uses Strings).

Craig

On Tue, 17 Aug 2004 05:28:10 -0700 (PDT), Robert Bowen <sy...@yahoo.com> wrote:
> Hello. I am using Torque to generate the persistent
> classes for my web application. Torque generates these
> classes based on an xml file, in which you specify the
> table name, column name and column type.
> 
> What I would like to do is use copyProperties() to
> copy from an ActionForm directly to my
> Torque-generated beans but of course, everything is a
> String in the ActionForm world, whereas in my
> persistence classes my date fields, for example, are
> Dates, not Strings, so copyProperties fails.
> 
> I have been looking all over the jakarta web site, the
> archives of this mailing list, etc. People seem to be
> talking about creating a bean that acts as a
> go-between, a DTO I suppose, that has the same fields,
> getters and setters as the ActionForm, and that you
> first copy the properties to the DTO.
> 
> But ... won't I have the same problem when trying to
> use copyProperties? Do I have to somehow use the
> ConvertUtils instead?
> 
> Any help much appreciated. I am using a single servlet
> to instantiate a bean of type 'x', copy the values
> from a form and save it in the database, so having to
> type 'gets' and 'sets' for every possible case ... is
> a waste of time, bad design, etc.
> 
> Many thanks!
> syg
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail is new and improved - Check it out!
> http://promotions.yahoo.com/new_mail
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: BeanUtils copProperties with Struts and Torque?

Posted by Marco Mistroni <mm...@waersystems.com>.
Not everything is string...

I am using tecnhnique that you r describing.. (though with hibernate on
backside..)

And I don't have all string fields..

-----Original Message-----
From: Robert Bowen [mailto:syg6@yahoo.com] 
Sent: 17 August 2004 13:28
To: commons-user@jakarta.apache.org
Subject: BeanUtils copProperties with Struts and Torque?

Hello. I am using Torque to generate the persistent
classes for my web application. Torque generates these
classes based on an xml file, in which you specify the
table name, column name and column type.

What I would like to do is use copyProperties() to
copy from an ActionForm directly to my
Torque-generated beans but of course, everything is a
String in the ActionForm world, whereas in my
persistence classes my date fields, for example, are
Dates, not Strings, so copyProperties fails.

I have been looking all over the jakarta web site, the
archives of this mailing list, etc. People seem to be
talking about creating a bean that acts as a
go-between, a DTO I suppose, that has the same fields,
getters and setters as the ActionForm, and that you
first copy the properties to the DTO. 

But ... won't I have the same problem when trying to
use copyProperties? Do I have to somehow use the
ConvertUtils instead?

Any help much appreciated. I am using a single servlet
to instantiate a bean of type 'x', copy the values
from a form and save it in the database, so having to
type 'gets' and 'sets' for every possible case ... is
a waste of time, bad design, etc.

Many thanks!
syg


		
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org