Since I just wrestled greatly with this particular beast, my $.02 follows.
Subclass whatever flavor of ActionForm you use, and give it a method with a
footprint like-
java.util.Date StringToDate(String)
{
}
This way you can do something like this in your action:
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
Myform mf = (Myform) form;
BizObject bo = new BizObject();
String dateText = mf.getDateString();
bo.setDate(mf.StringToDate(dateText);
// etc
}
This works very well unless internationalizing your app because the converter
needs a DateFormat defined to read the String correctly. And I am, so I need
to come up with something.
I don't suppose there is a version of BeanUtils that lets the user pass a
DateFormat into copyProperties :-)???
-Joe
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 26, 2004 3:58 AM
> To: Struts Users Mailing List
> Subject: RE: Handling Date objects in ActionForm gracefully
>
>
>
>
> +1
> I also suggest this approach to keep the date as string
> during posts and convert them to date object when porcessing
> the entered dates, surely not in the Form.
>
> Depends on what you really want to achieve. Would suggest
> the KISS rule..:-)
>
>
>
>
>
> "Robert Taylor" <[EMAIL PROTECTED]> on 03/25/2004 08:53:31 PM
>
> Please respond to "Struts Users Mailing List"
> <[EMAIL PROTECTED]>
>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> cc: (bcc: Anuj Upadhyay/Jeppesen/TMC)
>
> Subject: RE: Handling Date objects in ActionForm gracefully
>
>
>
> +1
>
> > -----Original Message-----
> > From: Mark Lowe [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, March 25, 2004 2:36 PM
> > To: Struts Users Mailing List
> > Subject: Re: Handling Date objects in ActionForm gracefully
> >
> >
> > Have it as a string and convert it to a date or calendar
> when you pass
> > it back to the model.
> >
> >
> > On 25 Mar 2004, at 20:28, Sreenivasa Chadalavada wrote:
> >
> > > All,
> > >
> > > We are facing a problem when we define java.util.Date field in
> > > ActionForm.
> > >
> > > Is there any way to override the default behavior provided by
> > > Struts?
> > >
> > > I very much appreciate your help!!
> > >
> > > Thanks and Regards,
> > > Sree/-
> > >
> > >
> > >
> --------------------------------------------------------------------
> > > ---
> > > -----------------
> > > This is a PRIVATE message. If you are not the intended recipient,
> > > please
> > > delete without copying and kindly advise us by e-mail of
> the mistake in
> > > delivery. NOTE: Regardless of content, this e-mail shall
> not operate to
> > > bind CSC to any order or other contract unless pursuant
> to explicit
> > > written agreement or government initiative expressly
> permitting the
> > > use of
> > > e-mail for such purpose.
> > >
> --------------------------------------------------------------
> ---------
> > > -----------------
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]