Announcement

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

    problem when using OptionDataSource in ListGridField

    SmartGWTPro smartgwtpro 4.1 build 2014-07-18

    dev mode & product mode

    when using ListGridField.setOptionDataSource for valueMap mapping, we met a very strange problem, TestCase has been attached.

    in a word, we have two fields for the same type valuemap mapping, for instance : userId -> userName

    this mapping of this way works only for :

    Code:
    ListGrid.setAutoFetchData(true)
    if you are using

    Code:
    grid.setAutoFetchData(false);
    grid.fetchData();
    it failed, both fields show the original value(userId)

    however, it there is only one field which using the OptionDataSource for mapping, it did work too.


    Code:
    ......
    
    public class TestEntryPoint implements EntryPoint {
    
    	@Override
    	public void onModuleLoad() {
    		ListGrid grid = new ListGrid();
    		grid.setWidth("100%");
    		
    		ListGridField f1 = new ListGridField("id1", "id1");
    		RestDataSource mds1 = new RestDataSource();
    		mds1.setDataFormat(DSDataFormat.JSON);
    		mds1.setDataURL("http://localhost:9080/aries/map.json");
    		f1.setAutoFetchDisplayMap(true);
    		f1.setValueField("k");
    		f1.setDisplayField("v");
    		f1.setOptionDataSource(mds1);
    		
    		ListGridField f2 = new ListGridField("id2", "id2");
    		RestDataSource mds2 = new RestDataSource();
    		mds2.setDataFormat(DSDataFormat.JSON);
    		mds2.setDataURL("http://localhost:9080/aries/map.json");
    		f2.setAutoFetchDisplayMap(true);
    		f2.setValueField("k");
    		f2.setDisplayField("v");
    		f2.setOptionDataSource(mds2);
    		
    		RestDataSource ds = new RestDataSource();
    		ds.setDataFormat(DSDataFormat.JSON);
    		ds.setDataURL("http://localhost:9080/aries/ds.json");
    		grid.setDataSource(ds);
    		
    		// failed
    		grid.setFields(f1, f2);
    		grid.setAutoFetchData(false);
    		grid.fetchData();
    		
    		// works
    //		grid.setFields(f1);
    //		grid.setAutoFetchData(false);
    //		grid.fetchData();
    		
    		// works
    //		grid.setFields(f1, f2);
    //		grid.setAutoFetchData(true);
    		
    		grid.draw();
    	}
    
    }
    Attached Files

    #2
    At the moment, you have RestDataSources defined with no field definitions, so that wouldn't be expected to work at all.

    Comment


      #3
      I add fields to all three RestDataSources however with no luck :

      Code:
         ......
      
        mds1.setFields(new DataSourceIntegerField("k"), new DataSourceTextField("v"));
      
         ......
         
        mds2.setFields(new DataSourceIntegerField("k"), new DataSourceTextField("v"));
      
         ......
        
        ds.setFields(new DataSourceIntegerField("id1"), new DataSourceIntegerField("id2"));

      after some investigation, I found there is a error throwed if I am using two optionDataSource field with :

      Code:
      grid.setAutoFetchData(false);
      grid.fetchData();
      a warning

      Code:
      10:21:28.663 [ERROR] [main] 10:21:28.662:WARN:RPCManager:Multiple RPCRequests with params attribute in one transaction - merging
      
      com.smartgwt.client.core.JsObject$SGWT_WARN: 10:21:28.662:WARN:RPCManager:Multiple RPCRequests with params attribute in one transaction - merging
      followed with a error :

      Code:
      10:21:28.715 [ERROR] [main] 10:21:28.713:TMR2:WARN:RPCManager:Found a REST request that appears to be in JSON format, but the response was not wrapped as configured by the jsonPrefix and jsonSuffix properties - aborting
      com.smartgwt.client.core.JsObject$SGWT_WARN: 10:21:28.713:TMR2:WARN:RPCManager:Found a REST request that appears to be in JSON format, but the response was not wrapped as configured by the jsonPrefix and jsonSuffix properties - aborting

      I don't known what is meaning of this error message because the response format is correct and works for other cases.

      but, finally, according to first warn, I adjust the code and let the second optionDataSource field use a different optionDataSource data url , let's say : "map1.txt"

      Code:
      RestDataSource mds1 = new RestDataSource();
      mds1.setDataFormat(DSDataFormat.JSON);
      mds1.setRecordXPath("/response/data");
      mds1.setDataURL("http://localhost:9080/aries/map.txt");
      
      
      RestDataSource mds2 = new RestDataSource();
      mds2.setDataFormat(DSDataFormat.JSON);
      mds2.setRecordXPath("/response/data");
      mds2.setDataURL("http://localhost:9080/aries/map1.txt");
      it works and error message has gone.

      Comment


        #4
        A grid with optionDataSources will by default submit all requests needed to load data - the data needed by optionDataSources and the data to actually populate the grid - using queuing.

        To understand the basics of queuing, read the QuickStart Guide section on queuing, then go on to the RestDataSource section on it to understand the different formats involved.

        For the jsonPrefix warning message, read the docs for RestDataSource.jsonPrefix.

        Comment


          #5
          I still don't know how to make the TestCase code work in mode of 2 optionDS fields with same url and setAutoFetchData(false);

          I have tried add field definitions to ds and other ways without success.

          maybe I miss something ?

          Comment

          Working...
          X