package com.acme.main.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.RestDataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.DSDataFormat;

public class Main implements EntryPoint {

    @Override
    public void onModuleLoad() {

        final RestDataSource dataSource = new RestDataSource() {
            @Override
            protected Object transformRequest(
                    com.smartgwt.client.data.DSRequest dsRequest) {
                // UNCOMMENTING THIS, IT WORKS
                // super.transformRequest(dsRequest);
                return dsRequest.getData();
            }

        };
        dataSource.setDataFormat(DSDataFormat.JSON);
        dataSource.setDataURL("gwt/data.js");

        // datasource fields initialization
        {
            final DataSourceIntegerField keyField = new DataSourceIntegerField(
                    "id", "ID");
            keyField.setPrimaryKey(true);
            final DataSourceTextField nameField = new DataSourceTextField(
                    "name", "Name");

            dataSource.setFields(keyField, nameField);
        }

        dataSource.fetchData(new Criteria());
    }
}
