Lee, Take a look at the classes in the org.apache.commons.beanutils.converters package. These classes are used to convert Strings to a particular type prior to calling the set method on a bean. There's not a DateConverter implementation (not sure why not), but it is a simple matter to write your own. If you do this, you will have to register your new converter with something like
ConvertUtils.register(new DateConverter(), Date.class); Regards, Mark Drew -----Original Message----- From: Lee Francis Wilhelmsen [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 09, 2004 6:10 AM To: [EMAIL PROTECTED] Subject: [Digester] Settng a java.util.Date bean property Hi I'm new to Digester and have got simple xml->java processing working based on some examples I found on www.onjava.com and www.javaworld.com. However, what I fail to see is how I can set a property of a bean if it is of type java.util.Date using a setDate(Date) bean method (xml date should be in RFC822 format)? I'm not sure this is a Digester problem (since it seems to use BeanUtils internally to do this), but I imagine someone, somewhere has done this using Digester (?). Anyway, I've been using: digester.addBeanPropertySetter("pattern/date", "date"); in my code where the property name is date, but this isn't working. The error can be seen below. I can only assume this has something to do with the fact that the java.util.Date class has no constructor matching a java.lang.String input and needs a DateFormatter to help, but how do you do that here? I haven't tested with other types apart from Strings (Integer, Boolean etc. - do they work as expected?). Any ideas how to get past this one greatly appreciated? Regards Lee Francis Wilhelmsen Here's the stack trace I get when running the program: 219 [main] DEBUG org.apache.commons.beanutils.ConvertUtils - Convert string 'Wed, 09 Jun 2004 09:19:00 GMT' to class 'java.util.Date' 219 [main] DEBUG org.apache.commons.beanutils.ConvertUtils - Using converter [EMAIL PROTECTED] 219 [main] ERROR org.apache.commons.digester.Digester - End event threw exception java.lang.IllegalArgumentException: argument type mismatch at java.lang.reflect.Method.invoke(Native Method) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.j ava:1789) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.j ava:1684) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:17 13) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019) at org.apache.commons.digester.BeanPropertySetterRule.end(BeanPropertySetterRul e.java:244) at org.apache.commons.digester.Digester.endElement(Digester.java:1058) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc her.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.commons.digester.Digester.parse(Digester.java:1548) at etc. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] NOTICE: This communication contains information which is confidential to Realm Business Solutions, Inc. or its subsidiary ("Realm"). If you are not the intended recipient of this communication, please delete and destroy all copies. If you are the intended recipient of this communication, you should not copy, disclose or distribute this communication without Realm's authority. Any views expressed in this communication are those of the individual sender, except where the sender specifically states them to be Realm's views. Except as required by law, Realm does not represent, warrant or guarantee that the integrity of this communication has been maintained nor that the communication is free of errors, virus, interception or interference. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
