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