struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Krygowski <james.krygow...@shaws.com>
Subject RE: java.util.Dates and Struts
Date Mon, 23 Dec 2002 17:24:27 GMT
Hi Rick-

I should have deleted the first block of code.  It's not exactly misleading,
but it unfocuses my point.  I apologise for that.  I'm spread a little thin
so the email quality control is suffering ;-).

The key thing to notice is this:

1.    HashMap values = new HashMap();
2.    values.put("today", "2002-03-17");

3.    MockForm mockForm = new MockForm();
4.    BeanUtils.copyProperties(mockForm, values);
5.    System.out.println(mockForm.getToday());
6.    Map beanProps = BeanUtils.describe(mockForm);
7.    System.out.println(beanProps.get("today"));


On line 4, the code successfully transforms a String into a Date and stores
it in the form MockForm.  On line 6, I try to get that value out of the
MockForm (where it is stored as a Date) and into beanProps which is a Map of
the Stringified values of all the getters on MockForm.  The date string that
ends up in beanProps is not formatted.

jk

> -----Original Message-----
> From: Rick Reumann [mailto:maillist@reumann.net]
> Sent: Monday, December 23, 2002 3:07 PM
> Cc: struts-user@jakarta.apache.org
> Subject: Re: java.util.Dates and Struts
>
>
> On Mon, 23 Dec 2002 11:49:04 -0500
> Jim Krygowski <james.krygowski@shaws.com> wrote:
>
> > This is my test:
> > ...
> > 	String input = null;
> >
> >       // check to make sure the datatype is right
> >       input = "2002-03-17";
> >       Date dateValue = (Date)ConvertUtils.convert(input, Date.class);
> >       assertTrue(dateValue instanceof Date);
>
> But where is this dateValue being used? You saying it's not converting
> java.util.Date to a String properly for you yet I don't see this Date
> being used anywhere to even allow it be converted to the String in the
> correct format.
>
> >
> >       // try to get a value from a Map
> > 	HashMap values = new HashMap();
> >       values.put("today", "2002-03-17");
> >       MockForm mockForm = new MockForm();
> >       BeanUtils.copyProperties(mockForm, values);
>
>
> Isn't your concern going the other direction that is having you
> stumped? In other words here you are just doing a String to String
> conversion. Why don't you create a Bean that has java.util.Date field
> and then do
> BeanUtils.copyProperties(mockForm, theObjectThatHasAdateField );
> Then try
>
> >       Map beanProps = BeanUtils.describe(mockForm);
> >       System.out.println(beanProps.get("today"));
>
>
>
> --
> Rick
>
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message