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/16 18:22:28 UTC

Am I the only one using java.util.Date?

My business layer bean has a field as java.util.Date (example:
birthDate). My form bean uses the String for this date (in this
example.. String birthDate). The problem is I can't seem to use
BeanUtils to copy the properties since it appears BeanUtils will only
convert a java.sql.Date by default (get
java.lang.IllegalArgumentException: argument type mismatch when using
java.util.Date) . I tried dealing with registering a custom Coverter I
wrote and registering it with ConvertUtils and below is a copy of the
message I posted concerning this problem.

I'm posting this question, though, because I'm curious how others have
dealt with this situation? Maybe using the BeanUtils or PropertyUtils
is not that common of a practice or most use a java.sql.Date as
opposed to java.util.Date? Having dates in form fields is common so
I'm curious how others transfer their form field dates to their
business model (as java.util.Date?).

Thanks for any info.

Below was Converter question I posted last night, in case anyone is
interested:

I'm still having a bit of trouble trying to use BeanUtils to copy
java.util.Date properties. It appears that it will work fine by
default with java.sql.Date but isn't set up by default for
java.util.Date (which I'm using for Dates in my business bean). I
build a class implements Converter interface and used the ConvertUtils
to register java.util.Date with this Converter. It works great
converting the String form properties to Dates as expected. The
question I have is how do I build a converter (or modify the existing
one) that will convert the Date properties to String properties when I
want to go the other way with the copyProperties (populate my DynaForm
from a business bean)? I tried modifying the covert method of the
Converter I created so that if the arg was a String property it would
covert and return a Date but the problem is this Converter never got
used when going the other direction (Date to String). Any ideas what
I'm doing wrong or what I can do to solve this problem?


-- 

Rick
mailto:maillist@reumann.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re[2]: Am I the only one using java.util.Date?

Posted by Rick Reumann <ma...@reumann.net>.
On Wednesday, October 16, 2002, 12:40:01 PM, kiuma wrote:

k> Since I'm connected to jboss I use java.sql.Date.

k> Then I pass values in millis and use a GregorianCalendar to manage dates.

   Thank you, but that's not really my question.

   I'm wondering more how others deal with getting their String
   versions of Dates into the correct Data type in their business bean
   and use BeanUtils also. (I know BeanUtils converts
   java.sql.Date but I'm wondering if others are using java.util.Date
   and if so how are they handling usiing
   BeanUtils.copyProperties(.. )... are they creating a custom converter?
   If so are they also using BeanUtils.copyProperties( ..) to copy
   back from their business object to their form bean using a
   Converter?

   I absolutely love the power of BeanUtils.copyProperties, I just
   find it surprising that others haven't run into issues using this
   with java.util.Date. (Hence my new post here because maybe I
   shouldn't be using this data type?). I'll dig in more with the
   issue of writing my own Converter and registering it (as described
   in my other post) but before I tackle that more I was just curious
   how others have dealt it with (why reinvent the wheel thing:)

   Thanks



-- 

Rick
mailto:maillist@reumann.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Am I the only one using java.util.Date?

Posted by kiuma <ki...@usa.net>.
Since I'm connected to jboss
I use java.sql.Date.

Then I pass values in millis and use a GregorianCalendar to manage dates.


Rick Reumann wrote:

>My business layer bean has a field as java.util.Date (example:
>birthDate). My form bean uses the String for this date (in this
>example.. String birthDate). The problem is I can't seem to use
>BeanUtils to copy the properties since it appears BeanUtils will only
>convert a java.sql.Date by default (get
>java.lang.IllegalArgumentException: argument type mismatch when using
>java.util.Date) . I tried dealing with registering a custom Coverter I
>wrote and registering it with ConvertUtils and below is a copy of the
>message I posted concerning this problem.
>
>I'm posting this question, though, because I'm curious how others have
>dealt with this situation? Maybe using the BeanUtils or PropertyUtils
>is not that common of a practice or most use a java.sql.Date as
>opposed to java.util.Date? Having dates in form fields is common so
>I'm curious how others transfer their form field dates to their
>business model (as java.util.Date?).
>
>Thanks for any info.
>
>Below was Converter question I posted last night, in case anyone is
>interested:
>
>I'm still having a bit of trouble trying to use BeanUtils to copy
>java.util.Date properties. It appears that it will work fine by
>default with java.sql.Date but isn't set up by default for
>java.util.Date (which I'm using for Dates in my business bean). I
>build a class implements Converter interface and used the ConvertUtils
>to register java.util.Date with this Converter. It works great
>converting the String form properties to Dates as expected. The
>question I have is how do I build a converter (or modify the existing
>one) that will convert the Date properties to String properties when I
>want to go the other way with the copyProperties (populate my DynaForm
>from a business bean)? I tried modifying the covert method of the
>Converter I created so that if the arg was a String property it would
>covert and return a Date but the problem is this Converter never got
>used when going the other direction (Date to String). Any ideas what
>I'm doing wrong or what I can do to solve this problem?
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Am I the only one using java.util.Date?

Posted by Brian Hickey <bh...@r-effects.com>.
Rick,

You are on the right track. A suggestion would be to break the month, day
and year out on your forms (makes nice-nice with html:select) and provide
the code to populate them in your form instance. The conversion is actually
quite simple:

public GregorianCalendar getStartDate()
{
  return new GregorianCalendar( this.getStartYear(), this.getStartMonth()-1,
this.getStartDay() );
}

This getter (exists in the same form instance) will hand off the startDate
as a java.util.Date to your (dyn)Action.

HTH

Brian

----- Original Message -----
From: "Rick Reumann" <ma...@reumann.net>
To: "Struts List" <st...@jakarta.apache.org>
Sent: Wednesday, October 16, 2002 12:22 PM
Subject: Am I the only one using java.util.Date?


> My business layer bean has a field as java.util.Date (example:
> birthDate). My form bean uses the String for this date (in this
> example.. String birthDate). The problem is I can't seem to use
> BeanUtils to copy the properties since it appears BeanUtils will only
> convert a java.sql.Date by default (get
> java.lang.IllegalArgumentException: argument type mismatch when using
> java.util.Date) . I tried dealing with registering a custom Coverter I
> wrote and registering it with ConvertUtils and below is a copy of the
> message I posted concerning this problem.
>
> I'm posting this question, though, because I'm curious how others have
> dealt with this situation? Maybe using the BeanUtils or PropertyUtils
> is not that common of a practice or most use a java.sql.Date as
> opposed to java.util.Date? Having dates in form fields is common so
> I'm curious how others transfer their form field dates to their
> business model (as java.util.Date?).
>
> Thanks for any info.
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>