struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: BeanUtil and Date conversion
Date Wed, 08 Jan 2003 06:36:27 GMT


On Tue, 7 Jan 2003, Dan Tran wrote:

> Date: Tue, 7 Jan 2003 22:27:34 -0800
> From: Dan Tran <danttran@hotmail.com>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: Struts Users Mailing List <struts-user@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:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message