I'm submitting a criteria query using FilterBuilder and AdvancedCriteria based on a RestDataSource that contains DataSourceDateTimeFields. The REST service requires that dates also include time because a day level granularity is not specific enough for my use case. The format of the date in the criteria JSON received by my REST service has time omitted i.e. the format is 'yyyy-MM-dd'. In the course of debugging, I've also viewed the JSON of the same criteria queries in the developer console and just printed out the results of encoding of the dsRequest criteria to JSON myself inside the transformRequest of the data source:
The results of the json serialization of the dates in the criteria is different for these three different views:
Output of GWT.log in transformRequest:
Output of the same request in the developers console:
The request that is sent to the REST service (shown in firebug):
The output that I get from serializing for the GWT.log is the output desired. It appears that the date encoding strategy is different depending on what is calling the serialization. I wouldn't mind serializing the criteria to Json myself in the transformRequest but I couldn't find the appropriate hook into the data structures to do this (also a complete Javascript neophyte). Since this is a DateTime field, I wasn't expecting to encounter issues with missing time when the criteria is transmitted to the server.
SmartGWT: 2.1
GWT: 2.0.3
Browser: Firefox, Chrome
Mode: any
Code:
public class MyRestDataSource extends RestDataSource { private DataSourceDateTimeField myDateTime; [...] protected Object transformRequest(DSRequest dsRequest) { if (dsRequest.getOperationType() == DSOperationType.FETCH) { Criteria criteria = dsRequest.getCriteria(); GWT.log("request criteria " + (new JSONObject(criteria.getJsObj())).toString()); } return super.transformRequest(dsRequest); }
Output of GWT.log in transformRequest:
Code:
00:00:25.797 [INFO] request criteria {"_constructor":"AdvancedCriteria", "operator":"and", "criteria":[{"fieldName":"myDateTime", "operator":"equals", "value":1271131200000}]}
Code:
data:{ operator:"and", criteria:[ { fieldName:"myDateTime", operator:"equals", value:new Date(1271131200000) } ] }
Code:
criteria {"fieldName":"myDateTime","operator":"equals","value":"2010-04-13"} operator and
SmartGWT: 2.1
GWT: 2.0.3
Browser: Firefox, Chrome
Mode: any