Make sure you are using Castor 0.9.4.1 and it should work properly for
you.
--Keith
D DV wrote:
>
> Hi,
>
> The way Castor converts string to date when the field type is defined
> as type="date" is not helpful for me as my date format is something
> like "dd:MM:yyyy" and Castor expects another format. So, I have
> planned to define my own FieldHandler using the class
> GenericFieldHandler.
>
> The <field> wad defined as :
>
> <field name="dateLastModification"
> type="string" handler="myconverter.DateFieldHandler">
> <bind-xml name="dateLastModification" node="element"/>
> </field>
>
> My DateFieldHandler class was defined as :
>
> public class DateFieldHandler extends GeneralizedFieldHandler {
>
> private static final SimpleDateFormat DateFormatter =
>
> new SimpleDateFormat("dd:MM:yyyy");
>
> static {
> DateFormatter.setLenient(false);
> }
>
> public Object convertUponGet(Object value) {
> return DateFormatter.format((java.util.Date) value);
> }
>
> public Object convertUponSet(Object value) {
> return DateFormatter.parse((String) value, new ParsePosition(0));
> }
> }
>
> When I ran, I have got the following message :
>
> unable to add 'dateLastModification' to <documentStandard> due to the
> following exception:
> >>>--- Begin Exception ---<<<
> java.lang.IllegalStateException: A call to #setFieldHandler (with a
> non-null value) must be made before calling this method.
> at org.exolab.castor.mapping.GeneralizedFieldHandler.setValue(Unknown
> Source)
> at org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(Unknown
> Source)
> at org.exolab.castor.xml.UnmarshalHandler.endElement(Unknown Source)
> at
> org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392)
> at
>
>org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1550)
> at
>
>org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1155)
> at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:387)
> at org.apache.xerces.framework.XMLParser.parse(XMLPar! ser.java:1099)
> at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
> at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
> at
>
>repository.RepositoryObjectLifecycleHandler.unmarshal(RepositoryObjectLifecycleHandler.java:35)
> at
>
>repository.RepositoryObjectLifecycleHandlerTestCase.main(RepositoryObjectLifecycleHandlerTestCase.java:28)
> >>>---- End Exception ----<<<
>
> The #setFieldHandler method is a method of the GenericFieldHandler.
> But I don't know how to call it in my DateFieldHandler class which is
> derived from GenericFieldHandler. And furthermore, I don't know if I
> really need to call it...
>
> Well, I have browsed the mail-list archive without success.
>
> Any idea is welcome !
>
> Thanks a lot for your help.
>
> Regards,
>
> Dominique
>
>
>
> ----------------------------------------------------------------------
> Yahoo! Mail -- Une adresse @yahoo.fr gratuite et en fran�ais !
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev