PDA

View Full Version : xmlreader not catching Date.class field types



cbruno
13 Aug 2009, 3:35 PM
I want a grid to read in Dates from my server (served as timestamps) -

I use xml to trasmit the model.

I add a Date to my ModelType in the following manner:


DataField lastmodfield = new DataField("lastmodified");
lastmodfield.setType(Date.class);
lastmodfield.setFormat("timestamp");
type.addField(lastmodfield);

I create the columnconfigs in the normal way:

ColumnConfig lastmodifiedcols = new ColumnConfig("lastmodified", "Last Modified", 160);
lastmodifiedcols.setMenuDisabled(true);
columns.add(lastmodifiedcols);

and I read in the xml this way:

String url = GWT.getHostPageBaseURL() + "statproject/get_dataframes?username=cbruno";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
HttpProxy<String> proxy = new HttpProxy<String>(builder);
XmlLoadResultReader<ListLoadResult<BaseModel>> reader = new XmlLoadResultReader<ListLoadResult<BaseModel>>(type);
final BaseListLoader<ListLoadResult<BaseModel>> loader = new BaseListLoader<ListLoadResult<BaseModel>>( proxy, reader);
ListStore<BaseModel> store = new ListStore<BaseModel>(loader);
loader.load();

my server returns xml with <lastmodified></lastmodified> containing the time stamp.

the problem is the "lastmodified" field does not show up in the grid. I found out why.

In XmlReader.java, in the read function, a Date type is not caught by this line

if(type.equals(Date.class)) {

//load date to model instance

}


if i change this to

if(type.toString().equals("class java.sql.Date") {

//load date to model instance

}


everything works fine.

What is going on?

sven
13 Aug 2009, 3:38 PM
Moving this to the help forum as this is a question and not a bugreport.

sven
13 Aug 2009, 3:43 PM
lastmodfield.setType(Date.class);

Is it possible that you imported java.sql.Date here? The type needs to be java.util.Date to work the default xmlreader.

cbruno
13 Aug 2009, 3:46 PM
yes that was the problem. I guess I need to be more careful about using Eclipse's Quickfix when importing stuff. Thank you!!!!