Announcement

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

    #16
    Then it seems like whether the fetch is coming from invalidateCache() or is the initial fetch, in both cases, you'd want to do the same thing.

    Comment


      #17
      Yes, that nicely completes the circle. Thanks.

      Comment


        #18
        TreeGrid.invalidateCache() will attempt to re-load the entire tree that is in the grid based on node expansions. I am noticing that the grid will re-send all parentNodeIDs requests to do so. Including nodes that do not return any data (edge of the tree leaf nodes).

        I am trying to avoid multiple requests going to the server by returning the entire tree on the root node. But even doing this, I see the leaf node requests being sent to the server even though there is nothing to return in which I simple return an empty set like this on the server
        Code:
                        DSResponse dsResponse = new DSResponse();
                        ArrayList arrayList = new ArrayList();
                        dsResponse.setData(arrayList.toArray());
                        dsResponse.setStartRow(0);
                        dsResponse.setEndRow(arrayList.size());
                        dsResponse.setTotalRows(arrayList.size());
                        return dsResponse;
        Is there any way to have the Grid not try to reload empty leaf nodes on a TreeGrid.invalidateCache() call? Is this possible through the DataSource.cacheData api?

        Code:
        Record[] cacheRecords = treeGrid.getDataSource().getCacheData();
        Does not seem to return anything after several node expansions/load on demand FETCHes?
        Last edited by JLivermore; 18 Sep 2014, 09:35.

        Comment


          #19
          See Tree DataBinding overview: to return a folder than has no children, return an empty Array for the childrenProperty.

          Comment


            #20
            See the docs for getCacheData() - it has nothing to do with ResultTree. APIs on ResultTree are how you would inspect the current set of loaded nodes.

            Comment


              #21
              I have figured out a solution to my issue - when doing a TreeGrid.invalidateCache() I would like to minimize the number of DSRequests being sent to the server so on the root node FETCH, I return the entire tree that *has been* loaded up too that point. But I was seeing additional DSRequests being sent for empty folder nodes (nodes that were expanded but did not have any children below). Those additional DSRequests were being sent even though the entire tree data was returned on the root node FETCH. It appears the TreeGrid keeps track of all load-on-demand requests and simply resends them.

              So to avoid the empty folder DSrequests being sent again upon a TreeGrid.invalidateCache() I setup a FolderOpenedHandler and a DataArrivedHandler for the TreeGrid that essentially removes the empty-load-on-demand request for empty folder nodes.

              Code:
                      treeGrid.addFolderOpenedHandler(new FolderOpenedHandler() {
                          @Override
                          public void onFolderOpened(FolderOpenedEvent event) {
                              TreeNode treeNode = event.getNode();
                              /*
                               * By unloading the children from the EDGE_OF_TREE nodes, TreeGrid.invalidateCache() will not send
                               * FETCHes for the EDGE_OF_TREE nodes that are empty and have been expanded.  This block sets up
                               * the emptyTreeNode variable to check in the DataArrivedHandler.
                               */
                              if(!treeGrid.getData().hasChildren(treeNode)) emptyTreeNode = treeNode;
                              else emptyTreeNode = null;
                          }
                      });
              Code:
                      treeGrid.addDataArrivedHandler(new DataArrivedHandler() {
                          @Override
                          public void onDataArrived(DataArrivedEvent event) {
                              if(treeGrid.getRecords() != null && treeGrid.getRecords().length > 0)
                                  treeGrid.getData().openFolder(Tree.nodeForRecord(treeGrid.getRecords()[0]));
                              modelMediator.setStatusBarLoadingEnd("Ready");
              
                              /*
                               * By unloading the children from the EDGE_OF_TREE nodes, TreeGrid.invalidateCache() will not send
                               * FETCHes for the EDGE_OF_TREE nodes that are empty and have been expanded.
                               */
                              if(emptyTreeNode != null) {
                                  if(!treeGrid.getData().hasChildren(emptyTreeNode)) {
                                      treeGrid.getData().unloadChildren(emptyTreeNode);
                                  }
                                  emptyTreeNode = null;
                              }
              
                          }
                      });

              Comment


                #22
                What the ResultTree remembers is which nodes were open, and it opens the same nodes. You can disable this behavior via autoPreserveOpenState.

                Again the correct way to return an empty folder and avoid a fetch for its children, as we covered a few post ago:

                See Tree DataBinding overview: to return a folder that has no children, return an empty Array for the childrenProperty.

                Comment


                  #23
                  I need the Open State to be preserved, so that is good. I tried several times trying to return an empty folder with children set to zero, but was not able to get it to work as expected.

                  I asked several times, but you keep pointing me to the Tree Data Binding javadoc. Can you post an example on how to return an empty folder with the children property set to zero?

                  Comment


                    #24
                    We're unsure how to make this more explicit - the default childrenProperty is "children" so we are literally talking about a one line call like this:

                    Code:
                    record.setAttribute("children", new ArrayList());
                    For server-side code, if you are working with a Map as the Record object, change setAttribute() to put().

                    Comment


                      #25
                      Hmmm yes, that's what I did as well. OK, I'm clear now, no confusion on my side. Thank you for the explicit example.

                      this is what I am returning from the server on an empty fetch as seen in the RPC tab from the dev console:
                      Code:
                      [
                          {
                              affectedRows:0, 
                              data:[
                                  {
                                      children:[
                                      ]
                                  }
                              ], 
                              endRow:1, 
                              invalidateCache:false, 
                              isDSResponse:true, 
                              queueStatus:0, 
                              startRow:0, 
                              status:0, 
                              totalRows:1
                          }
                      ]
                      Which is what you gave me in the example?

                      What I see in this case is another node under the node I clicked on, which is an empty node and I'm returning the above DSResponse. Not what I expected?
                      Last edited by JLivermore; 23 Sep 2014, 04:58.

                      Comment


                        #26
                        Does the DSResponse I posted above look ok? Because what I see in the TreeGrid after this DSResponse goes back is another empty node under the original node I expanded. Returning this dummy record creates a new subnode?

                        Just so we are clear, on the server this is the code:
                        Code:
                                        DSResponse dsResponse = new DSResponse();
                                        Map<String, Object> record = new HashMap<String, Object>();
                                        record.put("children", new ArrayList<>());
                                        ArrayList arrayList = new ArrayList();
                                        arrayList.add(record);
                                        dsResponse.setData(arrayList);
                                        dsResponse.setStartRow(0);
                                        dsResponse.setEndRow(arrayList.size()-1);
                                        dsResponse.setTotalRows(arrayList.size());
                        
                                        return dsResponse;
                        I've attached an image outlining in red, the unexpected sub node.
                        Attached Files
                        Last edited by JLivermore; 23 Sep 2014, 07:45.

                        Comment

                        Working...
                        X