Announcement

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

    RestDataSource protocols

    Hi,

    I'm using RestDataSource with remote JSON sources for a while now and it works just fine in getParams protocol.

    I would now like to use postParams or postMessage for specific sources and it does not seem to work. The data source keeps issuing GET queries to my address.

    Code:
    RestDataSource dataSource = new RestDataSource();
    dataSource.setFetchDataURL("/fetch");
    dataSource.setDataProtocol(DSProtocol.POSTPARAMS);
            
    ListGrid grid = new ListGrid();
    grid.setDataSource(dataSource);
    grid.fetchData();
    When I open the page, the browser seems to issue only GET

    Code:
    GET http://localhost:8080/fetch?_operationType=fetch&_startRow=0&_endRow=75&_te…0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml 404 (Not Found)
    I tried this with various stable builds from SmartGWT 3.0p and 3.1p and it always had this behaviour.

    Can you tell me if I missed something ?

    Thanks !

    Yannick

    SmartGWT 3.0p and 3.1p
    Browser: Chrome 24.0.1312.57
    GWT 2.5.0

    #2
    You could try setting an operation binding for fetch like they do here:

    http://blog.bigpixel.ro/2011/03/working-easier-with-datasources-in-smartgwt/

    Comment


      #3
      Aklopp is correct - the right way to handle this would be a specific fetch operationBinding with a specified dataProtocol

      Regards
      Isomorphic Software

      Comment


        #4
        This worked.

        Code:
               RestDataSource dataSource = new RestDataSource();
                dataSource.setFetchDataURL("/fetch");
        
                OperationBinding fetch = new OperationBinding();
                fetch.setOperationType(DSOperationType.FETCH);
                fetch.setDataProtocol(DSProtocol.POSTPARAMS);
        
                dataSource.setOperationBindings(fetch);
        
                ListGrid grid = new ListGrid();
                grid.setDataSource(dataSource);
                grid.fetchData();
        This caused an actual POST query to my URL.

        Thanks, I will now try to implement this on my actual DataSource.

        Best regards,

        Yannick

        Comment


          #5
          In fact, this is the definitive way to achieve what you need - we've updated the docs for RestDataSource.dataProtocol to emphasise this

          Comment


            #6
            Hi all,

            While I was implementing my explicit operation bindings, I noticed that there seems to be an issue with RestDataSource data format management.

            Here's an my example:

            Code:
                 (in the constructor of a data source class extending RestDataSource)
                    [...]
            
                    this.setSendMetaData(true);
                    this.setFields(fieldId, fieldEntityId, fieldParent, fieldEnabled);
                    // this.setDataFormat(DSDataFormat.JSON);
            
                    /*
                     * Specific operation bindings override global data source protocol and format.
                     * see http://forums.smartclient.com/showthread.php?t=25460
                     */
            
                    String dataUrl = computeDataURL(daoIdentifier, parameters);
            
                    OperationBinding fetchOperation = new OperationBinding();
                    fetchOperation.setOperationType(DSOperationType.FETCH);
                    fetchOperation.setDataProtocol(DSProtocol.GETPARAMS);
                    fetchOperation.setDataFormat(DSDataFormat.JSON);
                    fetchOperation.setDataURL(dataUrl);
            
                    this.setOperationBindings(fetchOperation);
            This will freeze the browser at runtime because the JSON response will be interpreted by the browser as XML.

            Indeed I also get "isc_dataFormat=xml" in the generated query string while I'd expect json.

            It seems that the Data Format set in the operation is not taken into account. If I uncomment the datasource setDataFormat, my query will be processed as JSON successfully.

            Could this be a bug of the RestDataSource implementation ?

            Best regards,

            Yannick

            Comment


              #7
              Are you hoping for mixed use of JSON and XML in different operations? This is possible starting from DataSource, but it's a non-goal for RestDataSource.

              Comment


                #8
                Hi,

                I'm not planning to use multiple formats for the operations. I'm just surprised that the protocol has to be set at operation level to be taken into account but the format has to be setup at data source level. I was just considering initializing all settings at the same level to avoid maintenance issues in the future...

                I'd expect anything set at the operation level to override things set at data source level for consistency ? That's why I'd prefer avoiding this.

                Best regards,

                Yannick

                Comment


                  #9
                  The default RestDataSource operationBindings all specify dataProtocol, but none specify dataFormat. That's why the DataSource-level dataFormat setting works to switch all bindings at once, but not dataProtocol. So it's already consistent in the way you expect.

                  And again as far as mixed dataProtocol for different operationTypes, this is not supported by RestDataSource, nor something we intend to add (haven't seen a use case for this).

                  Comment

                  Working...
                  X