Hello Charles,
> I'm trying to change the date format in the marshalled xml file using a
> FieldHandler, without success. Be grateful if someone could point me in the
> right direction, I have the feeling I'm barking up the wrong tree.
let's see, if this example works for you:
JDO...
import java.util.Date;
public class TestObj
{
public Date _date1;
}
Mapping file...
<field name="_date1" handler="MyDateFieldHandler" type="java.lang.String"
direct="true">
<bind-xml name="Date1"/>
</field>
FieldHandler...
public class MyDateFieldHandler extends GeneralizedFieldHandler
{
private static final DateFormat _fmt = new SimpleDateFormat("dd.MM.yyyy");
public MyDateFieldHandler()
{
}
public Object convertUponGet(Object value)
{
if (value == null)
return null;
return _fmt.format(value);
}
public Object convertUponSet(Object value)
{
if (value == null)
return null;
String dateStr = (String) value;
try {
Date date = (Date) _fmt.parse(dateStr);
return date;
} catch(ParseException e) {
throw new RuntimeException(e);
}
}
public Class getFieldType()
{
return java.util.Date.class;
}
}
Please note, you have to use the binding type "java.lang.String" regardless of the
actual used JDO variable type.
Regards,
Martin
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user