Thanks Joe

When you say - 
>this is a limitation of the BeanUtils design 
>model.  It assumes for any given process (instance of BeanUtils), a 
>single conversion strategy applies to all objects of a given type.

Do you mean that the converter applies thru my all application?
As much as I know - copyProperties() is a static method of BeanUtils so
I'm don't really know where (if at all) BeanUtils is instanciated.

Thanks
Rivka


-----Original Message-----
From: Joe Germuska [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 01, 2005 3:55 PM
To: Rivka Shisman; Struts Users Mailing List
Subject: Re: custom date converters

At 3:27 PM +0200 9/1/05, Rivka Shisman wrote:
>Hi friends
>
>
>
>I'm not sure I understand the use of custom converters:
>
>
>
>If for example I have 2 VO's and each has a Timestamp property. But -
>each one takes a different date format from the user. Do I need a
>different StringToTimestamp converter for each one? If yes - how does
>BeanUtils.copyProperties() know which converter to use (both the above
>properties are the same type - Timestamp)?

It does not.  Frankly, this is a limitation of the BeanUtils design 
model.  It assumes for any given process (instance of BeanUtils), a 
single conversion strategy applies to all objects of a given type.

I have solved this sometimes by writing a Converter which expects a 
few specific variations of a date format and then tests the string 
length to look up the format string -- obviously this is imperfect, 
but it may work for you.

(something like this:

if (str.length() == 10) {
        // parse date using "mm/dd/yyyy"
} else if (str.length() == 8) {
        // parse date using "hh:mm a"
} else {
    throw new IllegalArgumentException("Unrecognized date format");
}

Joe
-- 
Joe Germuska            
[EMAIL PROTECTED]  
http://blog.germuska.com    
"Narrow minds are weapons made for mass destruction"  -The Ex


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

Reply via email to