You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/10/09 00:15:30 UTC
using PropertyUtils with DynaActionForm
According to what I read in the archives I should be able to use the
copyProperties method in PropertyUtils to transfer DynaActionForm
properties to another bean. However, every time I try this, I get the
following thrown as an Exception:
java.lang.NoSuchMethodException: Unknown property 'class'
The code in the Action looks like this:
DynaActionForm f = (DynaActionForm)form;
CheckDTO checkDTO = new CheckDTO();
try {
PropertyUtils.copyProperties( checkDTO, f );
}
catch( Exception e ) {
ErrorLogging.info( "ManualVoidAction: insertManualCheck copyProperties: "+e );
}
Any ideas what I could be doing wrong? I searched the Struts archives
and couldn't find much.
Thanks for any help.
--
Rick
mailto:maillist@reumann.net
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re[2]: using PropertyUtils with DynaActionForm
Posted by Rick Reumann <ma...@reumann.net>.
On Tuesday, October 8, 2002, 6:35:35 PM, Eddie wrote:
EB> If both objects have accessors that support the same types,
EB> PropertyUtils should work fine. If they don't you'll want to use
EB> BeanUtils instead.
Thanks Eddie, BeanUtils did the trick.
I'm wondering is it a bad idea to have your value object or DTO
bean have properties of all Strings that match up exactly with the
FormBean String properties and then also include your "more
appropriate" datatypes in this DTO as well that will do the
conversions from the String properties?
For example in my DynaActionForm and in my DTO I'd have the
property
private String birthDateString
Then in the DTO I'd also have the regular:
private Date birthDate;
with the method:
getBirthDate() {
//converts the String birthDateString into a birthDate
Is it common practice to do the above? It seems to be a nice easy
way to use the PropertyUtils and also get the conversions you
need.
EB> BeanUtils.copyProperties(destBean, srcBean);
EB> It'll introspect and do conversions ... and you can register additional
EB> conversions, if needed. Check out the javadocs.
--
Rick
mailto:maillist@reumann.net
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: using PropertyUtils with DynaActionForm
Posted by Eddie Bush <ek...@swbell.net>.
If both objects have accessors that support the same types,
PropertyUtils should work fine. If they don't you'll want to use
BeanUtils instead.
BeanUtils.copyProperties(destBean, srcBean);
It'll introspect and do conversions ... and you can register additional
conversions, if needed. Check out the javadocs.
Rick Reumann wrote:
>According to what I read in the archives I should be able to use the
>copyProperties method in PropertyUtils to transfer DynaActionForm
>properties to another bean. However, every time I try this, I get the
>following thrown as an Exception:
>
>java.lang.NoSuchMethodException: Unknown property 'class'
>
>The code in the Action looks like this:
>
>DynaActionForm f = (DynaActionForm)form;
>CheckDTO checkDTO = new CheckDTO();
>try {
> PropertyUtils.copyProperties( checkDTO, f );
>}
>catch( Exception e ) {
> ErrorLogging.info( "ManualVoidAction: insertManualCheck copyProperties: "+e );
>}
>
>Any ideas what I could be doing wrong? I searched the Struts archives
>and couldn't find much.
>
>Thanks for any help.
>
--
Eddie Bush
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>