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/11 20:17:19 UTC
Re[3]: Struts forms best practice
On Friday, October 11, 2002, 2:02:11 PM, Craig wrote:
CRM> * Form bean property is a String.
<SNIP>
CRM> * Value/DTO objects would use the native data types
CRM> (java.util.Date in this case). Property name would
CRM> be the same "birthDate".
<SNIP>
CRM> * Either use a copyProperties method or write a custom
CRM> helper method to copy all the individual properties.
<SNIP>
Thanks Craig. It seems like if you do like above (using the
String birthDate in the form bean, and the native Date
'birthDate' in the model bean, then you don't get the benefit of
using the BeanUtils.copyProperties() method? I must be messing
something up because BeanUtils.copyProperties() seems to crap
out on me if I have native java.util.Date birthDate and form
bean property birthDate. Even if I want to use a helper method
to do the conversion, it seems like I have to throw out the
BeanUtils.copyProperties() if I want to have a form bean String
and java.util.Date with the same field name? What I'd like to
be able to do is using the copyProperties() of BeanUtils to copy
over all the Strings in the form bean to the String (or ints) in
the value object and then use a helper to deal with the Strings
that need to be converted to Dates. The problem I'm running into
is it seems to be an 'either' 'or' deal. Either, I make sure
their is a Date as a String also in my model bean or else I use
helper class to convert everything and not use the
BeanUtils/PropertyUtils. Is there a way around this? (besides
doing what I've done and have two versions of the date object in
the value object... one as a String and one as a java.util.Date)
?
Thanks again
--
Rick
mailto:maillist@reumann.net
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re[4]: Struts forms best practice
Posted by Rick Reumann <ma...@reumann.net>.
On Friday, October 11, 2002, 2:58:44 PM, Craig wrote:
CRM> Without knowing what "crap out on me" means, it's impossible to diagnose
CRM> this. Are you getting an exception so you can look at a stack trace?
I didn't know BeanUtils.copyProperties() should be able to take a
String date and can convert it into a java.util.Date. For some
reason when I try using BeanUtils.copyProperties() and I have a
java.util.Date that needs to be populated from a String, I get a
java.lang.IllegalArgumentException: argument type mismatch
error. The String version of the date is in MMddyyyy format in
the form bean. I noticed when looking at ConvertUtils that it
doesn't seem to mention that java.util.Date is provided by
default (looks like only java.sql.Date is). Maybe that's the
cause of the argument type mismatch (since I'm using
java.util.Date)? Thanks for the heads up into looking at
ConvertUtils.register(). Maybe that will help if I read more on
how to register my own conversion.
Thanks for the help so far.
--
Rick
mailto:maillist@reumann.net
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re[3]: Struts forms best practice
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Fri, 11 Oct 2002, Rick Reumann wrote:
> Date: Fri, 11 Oct 2002 14:17:19 -0400
> From: Rick Reumann <ma...@reumann.net>
> To: Craig R. McClanahan <cr...@apache.org>
> Cc: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re[3]: Struts forms best practice
>
>
>
> On Friday, October 11, 2002, 2:02:11 PM, Craig wrote:
>
>
> CRM> * Form bean property is a String.
> <SNIP>
> CRM> * Value/DTO objects would use the native data types
> CRM> (java.util.Date in this case). Property name would
> CRM> be the same "birthDate".
> <SNIP>
> CRM> * Either use a copyProperties method or write a custom
> CRM> helper method to copy all the individual properties.
> <SNIP>
>
> Thanks Craig. It seems like if you do like above (using the
> String birthDate in the form bean, and the native Date
> 'birthDate' in the model bean, then you don't get the benefit of
> using the BeanUtils.copyProperties() method?
Why not? BeanUtils.copyProperties() will automatically do the
String->Date conversion for you when copying from the form bean to the
value object. There's a default converter for this purpose built in, but
you can replace it with your own if you want (ConvertUtils.register()).
> I must be messing
> something up because BeanUtils.copyProperties() seems to crap
> out on me if I have native java.util.Date birthDate and form
> bean property birthDate.
Without knowing what "crap out on me" means, it's impossible to diagnose
this. Are you getting an exception so you can look at a stack trace?
> Even if I want to use a helper method
> to do the conversion, it seems like I have to throw out the
> BeanUtils.copyProperties() if I want to have a form bean String
> and java.util.Date with the same field name? What I'd like to
> be able to do is using the copyProperties() of BeanUtils to copy
> over all the Strings in the form bean to the String (or ints) in
> the value object and then use a helper to deal with the Strings
> that need to be converted to Dates. The problem I'm running into
> is it seems to be an 'either' 'or' deal. Either, I make sure
> their is a Date as a String also in my model bean or else I use
> helper class to convert everything and not use the
> BeanUtils/PropertyUtils. Is there a way around this? (besides
> doing what I've done and have two versions of the date object in
> the value object... one as a String and one as a java.util.Date)
> ?
>
> Thanks again
>
>
>
> --
>
> Rick
> mailto:maillist@reumann.net
>
>
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>