Ronald:

For what it's worth, here's my ValueUtils.java which has a couple of
conversion routines for dates, etc., in it.  Bear in mind that I'm no
more of a Java expert than I am a Struts expert.

Just to be complete, here is a snippet of code from one of my Action
classes that invokes a couple of the ValueUtils methods:

BeanUtils.populate(paymentForm,payment.describe());
paymentForm.setDateProcessed(ValueUtils.getLocalizedDateString(payment.g
etDateProcessed(),
        locale));
paymentForm.setAmount(ValueUtils.getLocalizedCurrencyString(payment.getA
mount(),
        locale));

I guess I should add that I have a custom .describe() method in my
"payment" bean, which I use instead of the standard
BeanUtils.describe().  This is recommended by a number of sources; you
code a custom .describe() method in your bean which returns a string
similar to that returned by BeanUtils.describe(), but only for fields
that do NOT require special handling.  Then, you use the methods in your
ValueUtils to "manually" convert the remaining fields.

I assume that you're familiar with the fairly standard method of
combining BeanUtils.describe() and BeanUtils.populate() to transfer
fields from one bean to another, but if not, write back and I'll point
you to the source I cribbed it from.  Check Ted Husted's webpage and the
Struts Tips on Jguru.

Hope this helps.
-----Original Message-----
From: Ronald Rotteveel [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, October 01, 2002 5:12 PM
To: Struts Users Mailing List
Subject: Re: Where do you convert (form) strings to other data types?


Thank you very much Charles!

I will try to do it with that. If anyone feels great today and feels
like adding some sample code it would make my day complete! ;-)

Regards,

Ronald


----- Original Message -----
From: "Charles McClain" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Tuesday, October 01, 2002 10:06 PM
Subject: RE: Where do you convert (form) strings to other data types?


> Ronald:
>
> I was too lazy before to look up Ted Husted's Struts Tip that I 
> referred to in my previous reply; it's actually in his "Struts 
> Catalog" of Struts design patterns on his webpage, 
> http://husted.com/struts/catalog.html . The title of the particular 
> design pattern in that document is 'Use a "populate" utility to 
> exchange data with value objects'.  Do a search on that string and 
> you'll find it.
>
> Regards,
>
>
> -----Original Message-----
> From: Ronald Rotteveel [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, October 01, 2002 11:18 AM
> To: Struts Users Mailing List
> Subject: Re: Where do you convert (form) strings to other data types?
>
>
> Thanks Charles,
>
> I even got a book ("Professional JSP Site Design") where Ted Husted is

> a co-author. I also found two lines of code on his website 
> (www.husted.com), but I still can't find out how this will do in my 
> example with the select input field. Should I convert it in de Action 
> class then?
>
> Hope to hear from anyone (I would like them most with some code 
> examples if that's possible...)
>
> Thank you all!
>
> Regards,
>
> Ronald Rotteveel
>
> ----- Original Message -----
> From: "Charles McClain" <[EMAIL PROTECTED]>
> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
> Sent: Tuesday, October 01, 2002 4:29 PM
> Subject: RE: Where do you convert (form) strings to other data types?
>
>
> > Ronald:
> >
> > In one of his Struts Tips on Jguru (sorry, I can't remember which 
> > one exactly), Ted Husted recommends creating a ValueUtils class for 
> > such supporting methods, both to separate them from the model and to

> > support re-use -- since such methods are likely to be needed in more

> > than one data transfer/conversion.
> >
> > -----Original Message-----
> > From: Ronald Rotteveel [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, October 01, 2002 7:04 AM
> > To: Struts Users Mailing List
> > Subject: Where do you convert (form) strings to other data types?
> >
> >
> > Dear all,
> >
> > I'm building a web application with the help of struts 1.0.2 (stable

> > release).
> >
> > In this webapp there are several forms with a date input field. I 
> > like
>
> > to make these input fields available in the following form:
> >
> > <select name="day">
> >     <option value="1">1</option>
> >     <option value="2">2</option>
> >     <option value="3">3</option>
> >                           etc.
> > </select>
> >
> > <select name="month">
> >     <option value="1">January</option>
> >     <option value="2">February</option>
> >     <option value="3">March</option>
> >                           etc.
> > </select>
> >
> > <select name="year">
> >     <option value="2002">2002</option>
> >     <option value="2003">2003</option>
> >     <option value="2004">2004</option>
> >                           etc.
> > </select>
> >
> > Now my problem is that date values are all stored in the database in

> > the timestamp format. How and where do I convert the values of the 
> > fields above into the right timestamp value. Secondly I also would 
> > like to know how I can set the above form input field in nice Struts

> > tags.
> >
> > I know these questions are pretty basic, but I'm a rookie at Struts 
> > and I've got two nice books where the are implementing Struts both 
> > at a bit different way, so I hope you all could help me out here!
> >
> > Thanks in advance!
> >
> >
> > Regards,
> >
> > Ronald Rotteveel
> >
> >
> > --
> > To unsubscribe, e-mail: 
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: 
> > <mailto:[EMAIL PROTECTED]>
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
> >
>
>
> --
> To unsubscribe, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

Attachment: ValueUtils.java
Description: Binary data

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to