Announcement

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

    ListGrid <-> RestDataSource

    Hi,
    I'm writing a python wrapper for smartclient.
    I updated to last version library today and i testing the various functionality before to release on github.

    I founded this problem:
    in previous version python reply to restdatasource with something like this, when rest fetch all data automaticallly:
    Code:
    {"response":{"msg":"no message",
                 "data":[{"id":1,
                          "name":"Name1",
                          "surname":"surname1",
                          "sex":"M",
                          "dateofbirth":"dd/mm/yyyy"}, 
                         {"id":2,
                          "name":"Name2",
                          "surname":"surname2",
                          "sex":"F",
                          "dateofbirth":"dd/mm/yyyy"}
                        ],
                  "status":"0",
                  "js":"window.alert(dataJ.msg); "}}

    With latest version the python reply with same string, but i get:

    The server failed to return a formatted response at all.


    #2
    This could happen if the RestDataSource were configured to expect XML and was provided JSOn instead. Perhaps by luck this still worked in a previous version.

    If you think your configuration is actually correct, try putting together minimal, runnable code that we can look at for this scenario.

    Comment


      #3
      Here is my code, it works with old version (2016/04), but doesn't work with new version.

      As you can see below the dataformat is setted to json:

      Code:
      var dts_0 = isc.RestDataSource.create({
               ​"width":"100%",
               [B]"dataFormat":"json"[/B],
               "ID":"dts_0",
               "height":"100%",
               "fields":[
                  {"name":"id","title":"id","canEdit":"false","width":"10%","type":"long","primaryKey":"true"},
                  {"width":"30%","type":"text","name":"name","title":"name"},
                  {"width":"30%","type":"text","name":"coddip","title":"coddip"},
                  {"width":"15%","type":"date","name":"dal","title":"dal"},
                  {"width":"15%","type":"date","name":"al","title":"al"}],
               "lg":function(){isc.RPCManager.sendRequest({
                     "params":{},
                     "callback":"myGlobalCallback(data)",
                     "actionURL":'customRequest/{"psc_event":"lg","psc_operation":"psc_operation","psc_object":{"object":"User"}}'});},
               "fetchDataURL":'customRequest/{"psc_event":"lg","psc_operation":"fetchDataURL","psc_object":{"object":"User"}}',
               "addDataURL":'customRequest/{"psc_event":"lg","psc_operation":"addDataURL","psc_object":{"object":"User"}}',
               "updateDataURL":'customRequest/{"psc_event":"lg","psc_operation":"updateDataURL","psc_object":{"object":"User"}}',
               "removeDataURL":'customRequest/{"psc_event":"lg","psc_operation":"removeDataURL","psc_object":{"object":"User"}}'});
      var lsg_1 = isc.ListGrid.create({
               "autoFitData":"horizontal",
               "autoFetchData":"true",
               "sortField":"name",
               "autoFitWidthApproach":"true",
               "emptyCellValue":"-NULL-",
               "height":300,
               "width":"100%",
               "alternateRecordStyles":"true",
               "dataPageSize":20,
               "dataSource":"dts_0",
               "headerHeight":30,
               "ID":"lsg_1",
               "cellHeight":25,
               "click":function(){isc.RPCManager.sendRequest({"params":{"record":lsg_1.getSelection()},
               "callback":"myGlobalCallback(data)",
               "actionURL":'manageRequest/{"psc_event":"click","psc_operation":"getDetail","psc_object":{"object":"User"}}'});}});
      var vly_2 = isc.VLayout.create({"width":"100%","ID":"vly_2","height":"100%"});
      vly_2.addMembers(dts_0);
      vly_2.addMembers(lsg_1);


      after page is loaded it make a request to server and it reply :

      Code:
      {"response":{
         "msg":"no message",
         "data":[{
               "id":31,
               "name":"root",
               "email":"g.t@somedomain.it",
               "coddip":"www",
               "password":"123",
               "dal":"01/01/1000",
               "al":"01/01/3000"}, {
               "id":32,
               "name":"a",
               "email":"a.bbbb@somedomain.it",
               "coddip":"eee",
               "password":"alessio",
               "dal":"01/01/1000",
               "al":"01/01/3000"}, {
               "id":34,
               "name":"s",
               "email":"s.ddd@somedomain.it",
               "coddip":"99",
               "password":"s",
               "dal":"01/01/1000",
               "al":"01/01/3000"}, {
               "id":35,
               "name":"r",
               "email":"r.ttt@somedomain.it",
               "coddip":"100",
               "password":"r",
               "dal":"01/01/1000",
               "al":"01/01/3000"}, {
               "id":36,
               "name":"g",
               "email":"g.ddddd@somedomain.it",
               "coddip":"101",
               "password":"1",
               "dal":"01/01/1000",
               "al":"01/01/3000"}, {
               "id":37,
               "name":"p",
               "email":"p.dddd@somedomain.it",
               "coddip":"111",
               "password":"p",
               "dal":"01/01/1000",
               "al":"01/01/3000"}],
          "status":"0",
          "js":"; "}}
      tnks for your reply.
      Last edited by peppicus; 22 May 2017, 06:34.

      Comment


        #4
        Hi,

        Your RestDataSource definition do not specify jsonPrefix and jsonSuffix properties. If not defined these properties default to following:
        jsonPrefix: "<SCRIPT>//'"]]>>isc_JSONResponseStart>>"
        jsonSuffix: "//isc_JSONResponseEnd"

        Received response is expected to be wrapped with these values. If it is not (your case) - DataSource treats it as incorrectly formatted response.

        You have several choices:
        1. wrap your response with these values on server (do not forget to change HTTP header "Content-Type" to "text/plain" because "wrapped response" is not valid JSON any more)
        2. in data source definition set jsonPrefix and jsonSuffix to some other values AND on server wrap response with it
        3. explicitly set jsonPrefix and jsonSuffix to empty strings in data source definition

        Regards,
        Alius
        Last edited by alius; 22 May 2017, 13:07.

        Comment


          #5
          Ok, now it works!

          tnks a lot.

          Comment


            #6
            Your immediate problem is most likely that you override transformRequest but either don't call Super() or modify the original request passed into that method rather than the one returned by Super. The bulk of the RestDataSource logic is in transformRequest, so if you skip it, you cripple the class mybkexperience
            Last edited by james65; 27 Jun 2019, 02:08.

            Comment

            Working...
            X