RestDataSource Fetch URL

I am adapting the Smart GWT Shocase example RestDataSource to a simple web service that fetches rows of data from a CSV file on a web server. The showcase example works fine for the “listGrid.setDataPageSize()” of rows fetched, but has issues if I scroll past that initial boundry.

For the sake of this post, let’s assume that there is 200 records in the table and that the grid page size is set to 50.

If I scroll down far enough to trigger a fetch operation against the URL assigned via the “restDataSource.setFetchDataURL()” will the URL be appended with startRow, endRow properties?

No, _startRow, _endRow properties by default - see the metadataPrefix property.

Note if you’re directly returning CSV you probably want to start with just DataSource, not RestDataSource. RestDataSource expects and implements a specific protocol, where the intent is for you to implement the protocol as it stands on your server. If you’re starting with a pre-existing protocol, use the approaches in the client-side data integration chapter (linked from the FAQ) to adapt that protocol.

I am doing this as an exercise to understand how the RestDataSource might work with some existing web services my customer has in-house - so thank you for the suggestion.

I have included a code fragment below.

        OperationBinding fetch = new OperationBinding();
        fetch.setOperationType(DSOperationType.FETCH);
        fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
        OperationBinding add = new OperationBinding();
        add.setOperationType(DSOperationType.ADD);
        add.setDataProtocol(DSProtocol.POSTMESSAGE);
        OperationBinding update = new OperationBinding();
        update.setOperationType(DSOperationType.UPDATE);
        update.setDataProtocol(DSProtocol.POSTMESSAGE);
        OperationBinding remove = new OperationBinding();
        remove.setOperationType(DSOperationType.REMOVE);
        remove.setDataProtocol(DSProtocol.POSTMESSAGE);
        restDS.setOperationBindings(fetch, add, update, remove);
        restDS.setSendMetaData(true);

        DataSourceTextField dsNALCode = new DataSourceTextField("nal_code", "Code");
        dsNALCode.setPrimaryKey(true);
        dsNALCode.setCanEdit(false);
        DataSourceTextField dsDescription = new DataSourceTextField("nomenclature", "Description");
        DataSourceIntegerField dsQuantity = new DataSourceIntegerField("quantity", "Quantity");
        restDS.setFields(dsNALCode, dsDescription, dsQuantity);
        restDS.setFetchDataURL("http://localhost:8080/csvtable");
        restDS.setAddDataURL("http://localhost:8080/csvtable");
        restDS.setUpdateDataURL("http://localhost:8080/csvtable");
        restDS.setRemoveDataURL("http://localhost:8080/csvtable");

        final ListGrid listGrid = new ListGrid();
        listGrid.setWidth(500);
        listGrid.setHeight(224);
        listGrid.setDataSource(restDS);
        listGrid.setEmptyCellValue("--");

        ListGridField codeField = new ListGridField("nal_code");
        ListGridField descField = new ListGridField("nomenclature");
        ListGridField qtyField = new ListGridField("quantity");
        listGrid.setFields(codeField, descField, qtyField);
        listGrid.setSortField(0);
        listGrid.setDataPageSize(50);
        listGrid.setAutoFetchData(true);

Based on your earlier feedback, I added “restDS.setSendMetaData(true);” to enable the sending of the meta data properties. Unfortunately, the properties are not being sent to the web service.

Is there something I missed?

With your current settings, they would be posted in XML, not added to the URL. Switch to getParams as the dataProtocol to add them to the URL.

Thank you - that was my issue. The web service and grid work well now.