Announcement

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

    TileGrid refresh

    Here's the scenario:
    - TileGrid populated with GwtRpcDataSource derived DS, setAutoFetchData(true);
    - data shows nicely on the grid when the grid is rendered;
    - I want to pull a new set of data:
    Step 1: ds.fetchData(); // i see the RPC call returned TileRecord[] has the right size and data but no visual change;
    Step 2: tileGrid.setData(tileRecords); // throws error: Cannot change configuration propperty 'data' to [Lcom.smartgwt.client.widgets.tile.TileRecord;@1214c59 after the component has been created.

    I've tried various combinations as: grid.redraw(), response.setInvalidateCache(true) in the fetch operation but nothing works.
    Note that in the DS the data is set via setAttribute("data", recArray) but i don't think this is a prob as initially the grid shows the data fine:
    public void onSuccess(List<AssetInfo> result) {
    response.setAttribute ("data", toTileRecords(result));
    processResponse(requestId, response);
    }
    Also I i don't use setAutoFetchData(true) I can't put anything into the tile grid later.
    Any suggestions, please? Thanks.

    #2
    TileGrid.setData was marked as not settable post-render and therefore you were seeing the error. This has been fixed in SVN.

    Sanjiv

    Comment


      #3
      Thanks, this seems to work now but still something is weird.
      Test 1:
      tileGrid.setAutoFetchData(true); //-> data shows OK
      .................
      tileGrid.addData(aTileRec); //ok, the new locally added item appears on the grid
      Test 2:
      tileGrid.setAutoFetchData(true); //-> data shows OK
      .................
      tileGrid.setData(tileRecsArray); //-> new data data shows ok
      .....................
      tileGrid.addData(aTileRec); // NOTHING, new item doesn't show up
      So after I use setData() I can't not add anymore local items.
      What am I missing here?

      Comment


        #4
        That seems like it would work so long as the record has a primaryKey when added.

        If not, can you put together a minimal test case?

        Comment


          #5
          Hi, i did more experiments and I was able to reproduce the behavior using a much simple scenario. I hope this will make it easier for you to reproduce it.
          Take this example http://www.smartclient.com/smartgwt/showcase/#tiling_editing ,which uses a client only DS, and add 2 buttons, addRecBtn and setDataBtn:

          addRecBtn_onClick{
          TileRecord aRec = new TileRecord();
          aRec.setAttribute(...); //set all reg attrs, use a diff fk
          .....
          tileGrid.addData(aRec); //now add the rec to the TileGrid
          }

          setDataBtn_onClick{
          TileRecord aRec = new TileRecord();
          aRec.setAttribute(...); //set all reg attrs
          .....
          TileRecord[] data=new TileRecord[1]; //let's use a simple test array
          data[0]=aRec;
          tileGrid.setData(data); //set data
          }

          The test:
          - app loads and the grid shows the orig tiles from the xml data;
          - click 'Add data' btn and the new rec shows up fine;
          - click 'Set Data', the new data is loaded, replaces the old recs, and shows up
          - click again 'Add data' --> FAILS, nothing happens anymore
          So after a tileGrid.setData() operation, addData() does not work anymore.
          I was able to reproduce this in various scenarios.
          This issue is a show stopper for us at this point. Any feedback is more than welcome. Thanks!

          Comment


            #6
            Any feedback please? This looks like DS/TileGrig bug that may be easy to spot for someone knowing the internal details. Thanks

            Comment


              #7
              I was able to reproduce it. We'll get back to you on this.

              In the future please post actual code for a standalone test case, or modifications to a showcase example that we can simply copy-paste and run. Posting pseudo-code means that we have to write the actual code to reproduce your testcase which will result in longer response times.

              Comment


                #8
                This is actually expected behavior. If you provide both a DataSource and a simple Array as the dataset (instead of using fetchData() to cause a ResultSet to be created), then data is saved to the DataSource unless saveLocally is set true.

                Your particular use case seems like kind of a bizarre series of calls - what are you trying to accomplish?

                Comment


                  #9
                  Ok, sorry for the pseudo-code, you are right.
                  Here's the real scenario:
                  - TileGrid with GwtRpcDataSource
                  - i want to be able to get data from server, refresh data from server but also be able to add records locally (new recs must show on the grid but I don't need anything send/saved on the server);
                  Steps:
                  1. load the grid with setAutoFetch(true) and it shows data from server OK;
                  2. add local records via tileGrid.addData(aRec), works OK ;
                  3. now i want drop the grid content and to reload data from server:
                  dataSrc.fetchData();
                  tileGrid.setData(retRecs); // if i don't do this, the new data does NOT show up; is this normal? do i really have to use setData() after fetchData() in order to force a refresh? (retRecs is a TileRecord[] extracted from the returned response)
                  Step 3 also works OK, i can see the reloaded data.

                  4. try again to add local recs via via tileGrid.addData(aRec) --> does NOT work anymore

                  So once i do a setData(recs), addData() has no effect anymore.
                  I found the same behavior in the modified showcase example and i thought is easier to reproduce there.
                  Thanks

                  Comment


                    #10
                    At step 3, just invalidateCache().

                    Comment


                      #11
                      I don't see invalidateCahe() for TileGrid (ListGrid has it but not the tile)
                      I also tried :
                      ...
                      response.setInvalidateCache(true);
                      processResponse(requestId, response);
                      ...
                      in the transformRequest() but no luck

                      Comment


                        #12
                        TileGrid.invalidateCache() has been added to SVN.

                        Comment


                          #13
                          Cool, thanks sjivan!

                          Comment


                            #14
                            Hello felixx,

                            I try to use the TileGrid with an RPC-Call in a dataSource. I receive the data in the AsyncCallback onSuccess() and set the data to the response. But the response never gets to the TileGrid. The TileGrid shows nothing.
                            Code:
                            RPC.getData(new AsyncCallback<List<MediaAssetTO>>() {
                            
                            				public void onFailure(Throwable arg0) {
                            					response.setStatus(RPCResponse.STATUS_FAILURE);
                            					processResponse(requestId, response);
                            				}
                            
                            				public void onSuccess(List<MediaAssetTO> result) {
                            					Log.trace("onSuccces");
                            					TileRecord[] records = new TileRecord[result.size()];
                            					for (int i = 0; i < records.length; i++) {
                            						MediaAssetTileRecord treeNode = new MediaAssetTileRecord(result.get(i));
                            						records[i] = treeNode;
                            					}
                            					response.setData(records);
                            					processResponse(requestId, response);
                            				}
                            			});

                            If I don't use the RPC-Call, but set the data and process, the data is shown.
                            Code:
                            	protected void executeFetch(final String requestId, final DSRequest request, final DSResponse response) {
                            		Log.trace("MediaAssetsDS: fetch");
                            		MediaAssetTileRecord treeNode = new MediaAssetTileRecord(new MediaAssetTO());
                            		TileRecord[] records = new TileRecord[1];
                            		records[0] = treeNode;
                            		
                            		response.setData(records);
                            		processResponse(requestId, response);
                            		
                            
                            		
                            
                            	}

                            Another way to get the data, that works, but isn't nice:
                            If I execute the fetch on the TileGrid manually (after invalidate the cache) and set the data with setData() on the TileGrid in the DSCallback, the data is shown in the TileGrid.

                            How did you got this working? Did you have a similar problem?

                            Thanks

                            Comment


                              #15
                              Here's what i have now:
                              Code:
                               public void onSuccess(List<AssetInfo> result) {
                                              response.setAttribute ("data", toTileRecords(result));
                                              processResponse(requestId, response);
                                          }
                              
                              private TileRecord[] toTileRecords(List<AssetInfo> inLst) {
                                      TileRecord[] outLst = new TileRecord[inLst.size()];
                                      TileRecord aRec;
                                      AssetInfo aDoc;
                                      for (int i = 0; i < outLst.length; i++) {
                                          aDoc=inLst.get(i);
                                          aRec = new TileRecord();
                                          aRec.setAttribute(MessageDefs.E_DOC_ID, aDoc.getId());
                                          aRec.setAttribute(MessageDefs.E_DOC_NAME, aDoc.getName());            
                                          outLst[i] = aRec;
                                      }
                              //System.out.println("rsz-"+inLst.size());
                                      return outLst;
                                  }

                              Comment

                              Working...
                              X