Announcement

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

    Listgrid json format

    Hi.
    SmartClient Version: v9.0_2013-07-03/LGPL Development Only (built 2013-07-03), both ff and chrome

    I cannot get ListGrid working with the json format described here:
    http://www.smartclient.com/smartgwt/...ataSource.html

    Code:
    public class SGwtUI implements EntryPoint {
        public void onModuleLoad() {
            VLayout main = new VLayout();
            ListGrid worklistGrid = new ListGrid();
            worklistGrid.setDataSource(WorklistDataSource.getInstance());
            worklistGrid.setAutoFetchData(true);
    
            main.addMember(worklistGrid);
            main.draw();
        }
    }
    Code:
    public class WorklistDataSource extends RestDataSource {
    
        public static final String ID = "worklistDS";
        private static final WorklistDataSource INSTANCE = new WorklistDataSource();
    
        public static WorklistDataSource getInstance() {
            return INSTANCE;
        }
        
        private WorklistDataSource() {
            setID(ID);
            setClientOnly(false);
            setFields(generateFields());
            setOperationBindings(generateOperationBindings());
        }
    
        private OperationBinding[] generateOperationBindings() {
            List<OperationBinding> operationBindings = new ArrayList<OperationBinding>();
    
            OperationBinding fetchOB = new OperationBinding(DSOperationType.FETCH, "servlet");
            fetchOB.setDataProtocol(DSProtocol.POSTPARAMS);
            fetchOB.setDataFormat(DSDataFormat.JSON);
            operationBindings.add(fetchOB);
    
            return operationBindings.toArray(new OperationBinding[operationBindings.size()]);
        }
    
        private DataSourceField[] generateFields() {
    
            List<DataSourceField> dsFields = new ArrayList<DataSourceField>();
    
            DataSourceField idField = new DataSourceIntegerField("id");
            idField.setPrimaryKey(true);
            dsFields.add(idField);
    
            DataSourceField typeField = new DataSourceTextField("code", "Type");
            dsFields.add(typeField);
    
            DataSourceField startField = new DataSourceDateField("started", "Started");
            dsFields.add(startField);
            return dsFields.toArray(new DataSourceField[dsFields.size()]);
        }
    
    }
    When the server response is:
    Code:
    {
    "response":{
      "status":0,
      "startRow":0,
      "endRow":1,
      "totalRows":2,
      "data":[
        {"id":768,"code":"d","started":"2013-11-20T14:34:39Z"},
        {"id":1242,"code":"p","started":"2013-11-20T14:34:45Z"}
      ]}
    }
    I get three empty rows with no error in dev console.

    But with
    Code:
    {
    "response":{
      "status":0,
      "startRow":0,
      "endRow":1,
      "totalRows":2,
      "data":{
        "WHATISTHIS":[
          {"id":768,"code":"d","started":"2013-11-20T14:34:39Z"},
          {"id":1242,"code":"p","started":"2013-11-20T14:34:45Z"}
        ]}
      }
    }
    it shows correct two rows.

    Has the format changed or do you have any idea what is causing this?
    Thanks
    Last edited by narvik; 15 Jan 2014, 11:40.

    #2
    We're not showing this issue. It suggests that, although you don't show it here, elsewhere you have code that is overriding the default recordXPath for RestDataSource, installing a ResponseTransformer, or in some other way interfering with normal behavior.

    Comment


      #3
      Thank you for the fast response!
      According to console my JSON recordXPath is '/response/data/*' which is the default for XML. That's really weird because the only thing I changed in the shared code was path to the servlet (I use '/projectname/servletname/list') and removed layout design.

      Code:
      21:22:45.614:XRP5:DEBUG:RPCManager:Result string for transaction 0: "{"response":{"status":0,"startRow":0,"endRow":1,"totalRows":2,"data":[{"id":768,"code":"d","started":"2013-11-20T14:34:39Z"},{"id":1242,"code":"p","started":"2013-11-20T14:34:45Z"}]}}"
      21:22:45.615:XRP5:INFO:RPCManager:rpcResponse(unstructured) results -->"{"response":{"status":0,"startRow":0,"endRow":1,"totalRows":2,"data":[{"id":768,"code":"d","started":"2013-11-20T14:34:39Z"},{"id":1242,"code":"p","started":"2013-11-20T14:34:45Z"}]}}"<--
      21:22:45.616:XRP5:INFO:RestDataSource:worklistDS:DataSource specifies jsonPrefix, but not present in response returned from server. Processing response anyway.
      21:22:45.616:XRP5:INFO:RestDataSource:worklistDS:DataSource specifies jsonSuffix, but not present in response returned from server. Processing response anyway.
      21:22:45.617:XRP5:DEBUG:xmlBinding:worklistDS:Raw response data: {
          "response":{
              "status":0, 
              "startRow":0, 
              "endRow":1, 
              "totalRows":2, 
              "data":[
                  {
                      "id":768, 
                      "code":"d", 
                      "started":"2013-11-20T14:34:39Z"
                  }, 
                  {
                      "id":1242, 
                      "code":"p", 
                      "started":"2013-11-20T14:34:45Z"
                  }
              ]
          }
      }
      21:22:45.618:XRP5:INFO:xmlBinding:worklistDS:JSON recordXPath: '/response/data/*', selected: Array[3]
      21:22:45.618:XRP5:DEBUG:xmlBinding:worklistDS:Validated dsResponse.data: [
          768, 
          "d", 
          "2013-11-20T14:34:39Z"
      ]
      21:22:45.621:XRP5:INFO:xmlBinding:worklistDS:dsResponse is: {data: Array[3],
      startRow: 0,
      status: 0,
      endRow: 3,
      totalRows: 3,
      httpResponseCode: 200,
      transactionNum: 0,
      clientContext: Obj,
      httpHeaders: Obj}
      21:22:45.640:XRP5:INFO:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):Received 3 records from server
      21:22:45.641:XRP5:DEBUG:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):full length set to: 3
      21:22:45.641:XRP5:DEBUG:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):integrating 3 rows into cache at position 0
      21:22:45.641:XRP5:INFO:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):cached 3 rows, from 0 to 3 (3 total rows, 3 cached)
      21:22:45.641:XRP5:INFO:ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):Cache for entire DataSource complete
      21:22:45.693:XRP5:INFO:redraws:isc_ListGrid_0_body:Scheduling redraw (dataChanged)
          [a]MathFunction.getStackTrace(_1=>undef, _2=>undef, _3=>undef, _4=>undef, _5=>undef)
          Canvas.$q9(_1=>"dataChanged", _2=>undef)
          Canvas.markForRedraw(_1=>"dataChanged", undef, undef, undef, undef)
          isc_Arra_map(_1=>"markForRedraw", _2=>"dataChanged", _3=>undef, _4=>undef, _5=>undef, _6=>undef)
          ListGrid.$25a(_1=>"dataChanged")
          ListGrid.redrawForDataChanged()
          ListGrid.dataChanged(_1=>undef, _2=>undef, _3=>undef, _4=>undef, _5=>undef)
          dataChangedObservation(operationType=>undef, originalRecord=>undef, rowNum=>undef, updateData=>undef, filterChanged=>undef, dataFromCache
      /**/=>undef)
          ResultSet.$ee(_1=>undef, _2=>undef)
          ResultSet.$390(_1=>Array[3], _2=>Obj)
          ResultSet.fetchRemoteDataReply(dsResponse=>Obj, data=>Array[3], request=>Obj)
          [c]Class.fireCallback(_1=>Obj, _2=>"dsResponse,data,dsRequest", _3=>Array[3], _4=>[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)], _5=>undef) on [Class RestDataSource]
          [a]MathFunction.fireCallback(_1=>Obj, _2=>"dsResponse,data,dsRequest", _3=>Array[3], _4=>undef)
          DataSource.fireResponseCallbacks(_1=>Obj, _2=>Obj, _3=>Obj, _4=>Obj)
          DataSource.$38b(_1=>Obj, _2=>Obj, _3=>Obj, _4=>Obj, _5=>Obj)
          DataSource.$377(_1=>Obj, _2=>Array[3], _3=>Obj)
          DataSource.$379(rpcResponse=>Obj, jsonText=>"{"response":{"status":0,"startRow":0,"en..."[201], rpcRequest=>Obj)
          ** recursed on [c]Class.fireCallback
      EDIT: adding setJsonRecordXPath("/response/data"); to WorklistDataSource constructor does not help :(
      Last edited by narvik; 15 Jan 2014, 12:56.

      Comment


        #4
        Ah, we see the issue. The default dataFormat at the DataSource level is XML. You've changed the dataFormat *for just fetch* to JSON, which means the recordXPath for XML is being used against the JSON format.

        This is a valid combination of settings - it would mean you'd like to fetch in JSON but do other operations in XML - but probably not what you intended. Just set the dataFormat for the DataSource as a whole to JSON to use JSON for all operations.

        Comment


          #5
          Your advice fixed the issue. Thanks again.

          Comment

          Working...
          X