You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Tran <da...@hotmail.com> on 2003/01/08 07:27:34 UTC
BeanUtil and Date conversion
Hi I am able to write a DateConverter using Converter interface to convert a specific date pattern String to Date object. This
way I can use BeanUtils.copyProperties to transparently convert a date string in my action form to my bean.
How do I write the converter to translate a Date object to String using the same pattern (ie from bean to form)???
Advice is greatly appreciated.
Happy coding
-D
Re: BeanUtil and Date conversion
Posted by Dan Tran <da...@hotmail.com>.
> > Hi I am able to write a DateConverter using Converter interface to
> > convert a specific date pattern String to Date object. This way I can
> > use BeanUtils.copyProperties to transparently convert a date string in
> > my action form to my bean.
> >
> > How do I write the converter to translate a Date object to String using
> > the same pattern (ie from bean to form)???
> >
>
> A short term strategy that might work is to create a custom Converter for
> java.lang.String that recognizes if the input object is a Date or not.
> You can base your code on the existing class
> (org.apache.commons.beanutils.converters.StringConverter) and add an
> instanceof check.
>
This is exactly what I am looking for
> Longer term, the Converter interface probably needs to have explicit
> methods for converting Object->String and String->Object.
>
I would be great to see this feature in BeanUtil in the future
Thanks and you are great
-D
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: BeanUtil and Date conversion
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Tue, 7 Jan 2003, Dan Tran wrote:
> Date: Tue, 7 Jan 2003 22:27:34 -0800
> From: Dan Tran <da...@hotmail.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: BeanUtil and Date conversion
>
> Hi I am able to write a DateConverter using Converter interface to
> convert a specific date pattern String to Date object. This way I can
> use BeanUtils.copyProperties to transparently convert a date string in
> my action form to my bean.
>
> How do I write the converter to translate a Date object to String using
> the same pattern (ie from bean to form)???
>
A short term strategy that might work is to create a custom Converter for
java.lang.String that recognizes if the input object is a Date or not.
You can base your code on the existing class
(org.apache.commons.beanutils.converters.StringConverter) and add an
instanceof check.
Longer term, the Converter interface probably needs to have explicit
methods for converting Object->String and String->Object.
> Advice is greatly appreciated.
>
> Happy coding
>
> -D
>
>
>
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>