Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    RestDataSource and Times/Dates

    I'm integrating with a non-servlet webservice and am having some trouble with Date and Time values and a RestDatasource. Are these fully implemented?

    It would be fantastic if you had an example of this working in the showcase (ie, include a "time", "date" and "datetime" in this example: http://www.smartclient.com/smartgwt/...ategory_simple or this one http://www.smartclient.com/smartgwt/...ation_category


    My understanding (please correct if I'm wrong) is the preferred way to transmit a "time" is with a string such as "09:21:00" and a "datetime" as a GMT formatted string such as "2012-03-18T09:21:00".

    This works fine with ListGrid components and DynamicForms. However, when I try and directly update a record without going through these Form/Grid components, it seems like the conversion logic has not been applied to the Record and the value stored in the Record is a String "09:21:00" - which will crash if I call getAsDateAttribute. If I do the same operation on a value that has been edited by a DynamicForm then the value returned is a Date.

    Now, I am able to get my Record to work as expected if I return a time as "new Date(12312412)" - which is not legal JSON (it is executable javascript). This works great for most things. But then I hit the Timezone issue. a "time" is stored on the client as a javascript Date with the time in localtime. This causes a headache because the I need to know the client's Timezone - also seems like a pretty horrid hack compared to returning a String.

    #2
    I've done some tracing through the code to understand why the String dates are not converted into JS Dates.

    The issue is that I have a field which contains my own DataSource type. The JS date conversion (which seems to be done in the validation code) does not happen because the code does not recurse into the embedded DS type.

    So, something like

    DataSourceA {
    someB : DataSourceB
    }

    DataSourceB {
    someDay : Date
    }

    will never get it's date converted into a JS object by the default code.

    Comment


      #3
      I fixed it by adding a script to the transformResponse. arguably this is not a complete fix. it should really keep recursing (in case there is deeply nested date).

      Code:
          transformResponse : function (dsResponse, dsRequest, jsonData) {
              var dsResponse = this.Super("transformResponse", arguments);
              function fixNested(record,ds) {
                   for (f in ds.fields){    
                     var type = ds.fields[f].type;
                     var fieldName = ds.fields[f].name;
                     var isMultiple = ds.fields[f].multiple;
                     var fieldDS = isc.DS.get(type);
                     if (fieldDS){
                          var value = record[fieldName];
                          var undef;
                          if (value!=undef && (!isMultiple || value.length>0)){
                          	  fieldDS.recordsFromObjects(value);
                          	}
                      	}
                      }
              };
              try { 
      	        var undef; 
      	        if (dsResponse.data!=undef){
      	            var data;
      	            if (isc.isAn.Array(dsResponse.data)){ 
      	                dsResponse.data.forEach(
      	  				    function(record){
      	                        fixNested(record,isc.DS.get(dsRequest.dataSource));      
      	                	}
      	                );
      	            }
      	        }}
              catch (e){
      	        console.log("Nested fix code crashed");
              }
              return dsResponse;
          }

      Comment

      Working...
      X