Announcement

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

    DataSource.copyRecord(Record) and updateCaches

    Referring to the example in the Javadoc for method "com.smartgwt.client.data.DataSource.updateCaches(DSResponse)", it provides an example using the DS.copyRecord(Record...).

    Code:
        // updatedRecord is the record we want to update
         Record record = supplyItemDS.copyRecord(updatedRecord);
         record.setAttribute("unitCost", 500);
         DSResponse dsResponse = new DSResponse();
         dsResponse.setData(record);
         dsResponse.setOperationType(DSOperationType.UPDATE);
         supplyItemDS.updateCaches(dsResponse);
    However, my findings show that if you use the copyRecord to copy a ListGridRecord and use the copied record for dsResponse.setData(record) as indicated by the example, you see the following error in the Development Mode console.

    Code:
    20:32:25.015 [ERROR] [xxx] 20:32:25.011:XRP9:WARN:Log:setData(): DSResponse data is expected to be an array of ListGridRecords. This allows the data to be displayed as expected in ListGrids bound to this dataSource.
    com.smartgwt.client.core.JsObject$SGWT_WARN: 20:32:25.011:XRP9:WARN:Log:setData(): DSResponse data is expected to be an array of ListGridRecords. This allows the data to be displayed as expected in ListGrids bound to this dataSource.
    If a ListGridRecord is being passed into the copyRecord, should a ListGridRecord be passed back?

    Thanks

    SmartClient Version: v9.1p_2014-05-19/Pro Deployment (built 2014-05-19)

    #2
    Hello,
    Just following up to make sure this post wasn't overlooked.
    Thanks

    Comment


      #3
      Hello and thanks for reporting this to us.

      We are currently having a look to see if we can make copyRecord return a ListGridRecord. More information to follow in this thread once resolved.

      Regards,
      Isomorphic Software

      Comment


        #4
        We've now made a change to DataSource.copyRecord() so that it returns an object of type ListGridRecord. You will have to download the latest nightly build of 9.1 or 10.0 for this fix.

        Regards,
        Isomorphic Software

        Comment


          #5
          Thank you, it is working as expected now.

          Comment


            #6
            SmartClient Version: v9.1p_2014-06-04/Pro Deployment (built 2014-06-04)

            I understand that the copyRecord creates a copy omitting selection/state related information, however, when you use the copied record to perform ds.updateCaches(...), would it clear the selection state of any grid currently displaying that record?

            My assumption was that it would not change the selection state of any grid currently displaying that record. Is that assumption correct?

            Furthermore, does this property, "com.smartgwt.client.widgets.grid.ListGrid.setReselectOnUpdate(boolean)", have relationship with that behaviour?

            Thanks

            Comment


              #7
              It would drop the selection, unless you had set reselectOnUpdate.

              Comment


                #8
                Thanks

                The Javadoc indicates reselectOnUpdate is true by default, so I expected this to be the default behaviour as we don't set this property explicitly.
                Last edited by stonebranch2; 6 Jun 2014, 19:27.

                Comment


                  #9
                  I've edited my last post, please disregard until we've had more time to investigate this further on our end.
                  Thanks

                  Comment


                    #10
                    I have an update and some sample code that reproduces the issue.

                    On the list grid, add the following RecordClickHandler.

                    Code:
                    addRecordClickHandler(new RecordClickHandler() {
                        @Override
                        public void onRecordClick(RecordClickEvent event) {
                            ListGridRecord[] selectedRecords = getSelectedRecords();
                            if (selectedRecords != null && selectedRecords.length == 1) {
                                String id = ClientUtils.getId(selectedRecords[0]);
                                DSRequest req = new DSRequest();
                                Criterion[] criterion;
                                criterion = new Criterion[] { new Criterion(PRIMARY_KEY, OperatorId.EQUALS, id) };
                                Criteria criteria = new AdvancedCriteria(OperatorId.AND, criterion);
                                getDataSource().fetchData(criteria, new DSCallback() {
                                    @Override
                                    public void execute(DSResponse response, Object rawData, DSRequest request) {
                                        RecordList rl = response.getDataAsRecordList();
                                        if (!rl.isEmpty()) {
                                            Record record = rl.first();
                                            DSResponse cacheResponse = new DSResponse();
                                            ListGridRecord lgr = getDataSource().copyRecord(record);
                                            cacheResponse.setData(lgr);
                                            cacheResponse.setOperationType(DSOperationType.UPDATE);
                                            [B]getDataSource().updateCaches(cacheResponse);[/B]
                                        }
                                    }
                                }, req);
                            }
                        }
                    });
                    If you comment out the call to "getDataSource().updateCaches(cacheResponse);", the record remains selected. If you don't comment out the call to "getDataSource().updateCaches(cacheResponse);", the record is deselected after making that call.

                    As an alternative, I used "ListGridRecord lgr = new ListGridRecord(record.getJsObj());" to create the ListGridRecord, and the same issue exists, so this issue might not be specifically related to copyRecord.

                    Regards

                    Comment


                      #11
                      Hello,
                      I wanted to follow up to make sure someone is still actively reviewing my issue described in the last post.
                      Thanks

                      Comment


                        #12
                        We're not reproducing this, and we can't actually run your code.

                        Are you claiming that you can update records via some other mechanism and the selection is preserved, and it's just updateCaches() where the selection is wiped out?

                        That doesn't make much sense, since the mechanism for reselectOnUpdate doesn't care whether the update comes from an updateCaches() call or something else (like grid inline edits). In fact it wouldn't be able to tell the difference..

                        Aside from making us able to reproduce this, you might check if you have some other logic, such as a dataChanged() handler, that is moving the selection around and hence undoing the effect of reselectOnUpdate.

                        Comment

                        Working...
                        X