Announcement

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

    ListGrid.fetchRelatedData()-> "matched tree relationship field by name" ->no callback

    Hi,
    I'm getting a warning message
    Code:
    WARN:RestDataSource:dsSlave:matched tree relationship field by name: id
    invoking ListGrid.fetchRelatedData () on a RestDataSource with the following code

    Code:
    slaveGrid.fetchRelatedData (masterRecord, masterDataSource.getInstance (), new DSCallback() {
    	
    	@Override
    	public void execute (DSResponse response, Object rawData, DSRequest request) {
    		GWT.log ("slave data retrieved");
    	}
    }, new DSRequest ());
    At the end the slave grid shows the right data (just fetched), but the callback is NEVER actually called (i.e. I never see the "slave data retrieved" on the GWT log).
    The Developer Console shows a SUCCESS status for the related request.

    This prevent me to do some post-processing after the slave data arrived.

    The datasources are defined as follows
    Code:
    //MASTER, having id "dsMaster"
    final DataSourceIntegerField dfId = new DataSourceIntegerField ("id", "Id");
    dfId.setPrimaryKey(true);
    dfId.setHidden(true);
    
    final DataSourceTextField dfCode = new DataSourceTextField ("code");
    dfName.setRequired (true);
    //other fields...
    
    setFields (dfId, dfCode, ...);
    Code:
    //SLAVE
    final DataSourceIntegerField pkField = new DataSourceIntegerField ("id");
    pkField.setPrimaryKey (true);
    
    final DataSourceIntegerField masterIdField = new DataSourceIntegerField ("masterId");
    masterIdField.setForeignKey ("dsMaster.id");
    //other fields...
    setFields (pkField, masterIdField, ...);
    What's wrong with my code?

    At client side I'm using
    SmartClient Version: 8.0/LGPL Development Only (built 2010-05-18)
    GWT 2.0.4
    Firefox 3.6.9

    at server side Grails 1.3.4

    Kind regards
    Davide
    Last edited by d.cavestro; 7 Oct 2010, 01:45.

    #2
    Any ideas?
    Isomorphic?

    Comment


      #3
      Maybe I have the answer.
      The documentation for ListGrid.filterData says about the callback parameter:

      "callback to invoke when a fetch is complete. Fires only if server contact was required; see fetchData for details"

      and ListGrid.fetchData(Criteria criteria, DSCallback callback) says

      "in some cases fetchData() will not need to context the server as the new criteria can be satisfied by performing a client-side filter against the currently cached set of data. You can determine whether criteria will cause a fetch by calling com.smartgwt.client.data.ResultSet.willFetchData."

      so I image I have to use the callback or synchronous code based on the results of willFetchData().
      Now I'll give it a try.
      Ah, if it works, I'll write a hundred times "i am the dunce".


      Davide

      Comment


        #4
        Originally posted by d.cavestro
        Maybe I have the answer.
        so I image I have to use the callback or synchronous code based on the results of willFetchData().
        Now I'll give it a try.
        Ah, if it works, I'll write a hundred times "i am the dunce".
        Yes, it works!

        I've developed some utility methods to harness the task of checking if there will be a server call and execute sync or async code

        Code:
        public static <T> void filterData (final ListGrid grid, final Criteria criteria, final Closure<T, ListGrid> c, final DSRequest requestProperties) {
            filterData (grid, criteria, new DSCallback() {
                
                @Override
                public void execute (DSResponse response, Object rawData, DSRequest request) {
                    c.call (grid);
                }
            }, c, requestProperties);
        
        }
        
        public static <T> void filterData (final ListGrid grid, final Criteria criteria, final DSCallback callback, final Closure<T, ListGrid> syncCallback, final DSRequest requestProperties) {
            final boolean sync = !grid.willFetchData (criteria);
            grid.filterData (criteria, callback, requestProperties);
            if (sync) {
                syncCallback.call (grid);
            }
        }
        where Closure is clearly defined to simply pass references to arbitrary code:
        Code:
        public interface Closure<O, I>{
        	O call(I input);
        }
        This way I can "instruct" the listGrid to execute the same code (or different, based on the method signature invoked) after the call to filterData.

        The same can be easily adapted for fetchData.

        Don't you think this strategy could be directly exposed by SmartGWT as a useful convention?
        If you think so, you are obviously free to use the above snippets.

        And now I can move to write a hundred times "i am the dunce":-)

        Cheers
        Davide

        Comment


          #5
          SmartGWT 2.2 LGPL

          I experience the same warning "... matched tree relationship field by name ...", despite I do not used a callback with ListGrid.fetchRelatedData(). I understand your solution but you did not say if the warning disappeared after managing to call the callback. I'd like to hear a comment from Isomorphic about that.

          Kind regards.

          Comment


            #6
            Originally posted by Catorcio
            SmartGWT 2.2 LGPL

            I experience the same warning "... matched tree relationship field by name ..." despite I do not used a callback with ListGrid.fetchRelatedData(). I understand your solution but you did not say if the warning disappeared after managing to call the callback. I'd like to hear a comment from Isomorphic about that.

            Kind regards.
            If I remember correctly, for what concerns the "matched tree relationship field by name" after updating SmartGWT to a recent nightly I saw a message that better explained the problem: I declared the "foreign key" field, but never added it to the slave datasource... something like
            Code:
            final DataSourceIntegerField pkField = new DataSourceIntegerField ("id");
            pkField.setPrimaryKey (true);
            
            final DataSourceIntegerField masterIdField = new DataSourceIntegerField ("masterId");
            masterIdField.setForeignKey ("dsMaster.id");
            
            //THE MISSING OF COMMENTED FIELD LEAD TO THE WARNING MESSAGE
            setFields (pkField, /*masterIdField,*/ ...);
            That way the library did its best to guess what field would act as a FK (and worked!!! based solely on the parameters passed to fetchRelatedData)... another reason for me to say "i am the dunce" :-)

            But maybe Isomorphic has more interesting explanations.

            Cheers
            Davide

            Comment


              #7
              Thanks for the quick replay but that's not the cause of my problem.
              As I do not find a solution (the programs runs correctly but I do not like to see the red warning line in the console) I resolved to using the prolixer

              Code:
               
              Criteria crit = new Criteria();
              crit.addCriteria("fk_field", record.getAttribute("pk_field"));
              listGrid.fetchData(crit) ;
              instead of
              Code:
               
              listGrid().fetchRelatedData(record, dataSource)  ;
              Kind regards.

              Comment

              Working...
              X