Thursday, February 14, 2008

ADF: Using ISO 8601 date (XSD) with Web Service DataControl

JavaBean mapping, generated by JDeveloper from the Web Service return type contains java.util.Date type for the XSD date based attributes, however java.util.Date can not handle ISO 8601 format (yyyy-MM-dd'T'HH:mm:ss) date.

What you need to do is to create a simple Java class extending java.util.Date which can handle ISO 8601 date format and specify it instead of standard java.util.Date in the JavaBean mapping file (to find the file you can use mapping file namespace: http://xmlns.oracle.com/adfm/beanmodel).

Here is the sample of simple Java ISODate class:


public class ISODate extends java.util.Date {
public ISODate(String value) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date d;

try {
d = sdf.parse(value);
} catch (ParseException e) {
throw new RuntimeException(e);
}

setTime(d.getTime());
}
}

2 comments:

Malabei said...
This comment has been removed by a blog administrator.
Ivan said...
This comment has been removed by a blog administrator.