Package com.smartgwt.client.data

Examples of com.smartgwt.client.data.RestDataSource


    setShowRollOverCanvas(true);
    initDataSource();
  }

  private void initDataSource() {
    RestDataSource dataSource = new RestDataSource();
    dataSource.setDataFormat(DSDataFormat.JSON);
    dataSource.setDataURL("Yasgui/autocompletionsInfo");
    setDataSource(dataSource);
    setAutoFetchData(true);
  }


        VLayout layout = new VLayout(15);
        layout.setAutoHeight();

        //overrides here are for illustration purposes only
        RestDataSource countryDS = new RestDataSource() {
            @Override
            protected Object transformRequest(DSRequest dsRequest) {
                return super.transformRequest(dsRequest);
            }
            @Override
            protected void transformResponse(DSResponse response, DSRequest request, Object data) {
                super.transformResponse(response, request, data);
            }
        };
        DataSourceTextField countryCode = new DataSourceTextField("countryCode", "Code");
        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);
        countryDS.setOperationBindings(fetch, add, update, remove);


        countryCode.setPrimaryKey(true);
        countryCode.setCanEdit(false);

        DataSourceTextField countryName = new DataSourceTextField("countryName", "Country");
        DataSourceTextField capital = new DataSourceTextField("capital", "Capital");
        countryDS.setFields(countryCode, countryName, capital);
        countryDS.setFetchDataURL("data/dataIntegration/xml/responses/country_fetch_rest.xml");
        countryDS.setAddDataURL("data/dataIntegration/xml/responses/country_add_rest.xml");
        countryDS.setUpdateDataURL("data/dataIntegration/xml/responses/country_update_rest.xml");
        countryDS.setRemoveDataURL("data/dataIntegration/xml/responses/country_remove_rest.xml");

        final ListGrid countryGrid = new ListGrid();
        countryGrid.setWidth(500);
        countryGrid.setHeight(224);
        countryGrid.setDataSource(countryDS);

      final AsyncCallback<DataSource> callback) {
    AsyncCallback<DataSourceDescriptor> callbackDSD = new AsyncCallback<DataSourceDescriptor>() {
      @Override
      public void onSuccess(DataSourceDescriptor result) {
        String s = "";
        RestDataSource dataSource = new RestDataSource() {
          @Override
          protected Object transformRequest(DSRequest dsRequest) {
            return super.transformRequest(dsRequest);
          }
        };

        dataSource.setID(result.get("name"));
        for (String param : result.keySet()) {
          dataSource.setAttribute(param, result.get(param), false);
        }
        String baseUrl = Window.Location.getProtocol() + "//"
            + Window.Location.getHost();

        String fetchURL = ((baseUrl + "/api/fetch/" + result
            .get("name")));
        String addURL = (baseUrl + "/api/add/" + result.get("name"));
        String updateURL = (baseUrl + "/api/update/" + result
            .get("name"));
        String removeURL = (baseUrl + "/api/remove/" + result
            .get("name"));

        OperationBinding remove = new OperationBinding(
            DSOperationType.REMOVE, removeURL);
        OperationBinding update = new OperationBinding(
            DSOperationType.UPDATE, updateURL);
        OperationBinding add = new OperationBinding(
            DSOperationType.ADD, addURL);
        OperationBinding fetch = new OperationBinding(
            DSOperationType.FETCH, fetchURL);

        fetch.setDataFormat(DSDataFormat.JSON);
        add.setDataFormat(DSDataFormat.JSON);
        update.setDataFormat(DSDataFormat.JSON);
        remove.setDataFormat(DSDataFormat.JSON);
        dataSource.setOperationBindings(fetch, add, update, remove);

        for (String field : result.getFields().keySet()) {
          DataSourceField f = new DataSourceField();
          f.setName(field);
          s += "<br> " + field + " ";
          Map<String, String> fieldMap = result.getFields()
              .get(field);
          for (String param : fieldMap.keySet()) {
            String value = fieldMap.get(param);
            s += param + "=" + value + " ";
            f.setAttribute(param, value);
          }
          dataSource.addField(f);
        }
        callback.onSuccess(dataSource);
      }

      @Override

TOP

Related Classes of com.smartgwt.client.data.RestDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.