Announcement

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

    willFetchData returns false but a server side fetch is performed

    Under certain conditions we have found that willFetchData returns false but then a call to fetchData actually does in fact perform a server side fetch.

    The conditions to cause this to happen are:
    1. more records/rows than the page size (I have page size to 100 and the problem only appears if there are more than 100 qualifying records)
    2. A criteria has been set on the listgrid before it has been drawn (before the 1st fetch). Again if no criteria has been set or if the criteria has been set after the grid is drawn and data alreadly loaded, the problem does not happen.

    Code:
            if (willFetchData(c)) {
                GWT.log("Fetch will cause a server-side fetch");
                fetchData(c);
            } else {
                GWT.log("Fetch will NOT cause a server-side fetch");
                fetchData(c, new DSCallback() {
                    @Override
                    public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                        GWT.log("Non-Fetching fetch callback!!!");
                    }
                });
            }
    When executing the code above, if the 2 conditions stated above are not met and the willFetchData returns false, all is good and the callback is not invoked. However, if the 2 conditions are met, then when willFetchData returns false, a server side fetch is still performed and the callback is executed.

    Output:
    Code:
    19:57:46.360 [INFO] [xxx] Fetch will NOT cause a server-side fetch
    19:57:47.305 [INFO] [xxx] Non-Fetching fetch callback!!!
    Using: SmartClient Version: v9.1p_2014-10-02/Pro Deployment (built 2014-10-02)
    Last edited by stonebranch1; 7 Oct 2014, 15:59.

    #2
    I have also been able to reproduce this with the Custom DataSources -> Simple showcase example by making the following code changes to setup the same required conditions:

    UserDataSource changes:
    Code:
    public DSResponse executeFetch(DSRequest req) throws Exception {
      long start = req.getStartRow();
      long end = req.getEndRow();
      List records = fetchRecords(req.getCriteria(), start, end);
      DSResponse resp = new DSResponse(records);
      resp.setTotalRows(data.size());
      resp.setStartRow(0);
      resp.setEndRow(records.size());
      return resp;
    }
    
    static {
      String[] firstNames = { "Charles", "Ron", "Grigori", "Tamara", "Betsy",
          "Gene", "Prya", "Ren", "John", "Fred", "George", "Jerry",
          "Mark", "Doug", "Phil", "Kathy", "Linda", "Jennifer", "Susan",
          "Sara", "Bob", "Craig", "Heather", "Gilbert" };
      String[] lastNames = { "Madigen", "Costanza", "Ognev", "Kane",
          "Rosenbaum", "Porter", "Sambhus", "Xian", "Jones", "Cooper",
          "Smith", "Kline", "Varley", "Sullivan", "Gardiner", "Fascal" };
      String[] jobTitle = { "Chief Operating Officer", "Manager Systems",
          "Technician", "Manager Site Services", "Secretary",
          "Manager Purchasing", "Line Worker",
          "Mobile Equipment Operator" };
      String[] type = { "full time", "contract", "part time", "full time",
          "part time", "contract", "part time", "full time" };
      float[] salary = { 20395, 18076, 12202, 21227, 11632, 17702, 12985,
          16402 };
    
      Random r = new Random();
      for (int ii = 0; ii < 225; ii++) {
        Map map = new HashMap();
        map.put("employeeId", new Integer(ii + 1));
        String fName = firstNames[r.nextInt(firstNames.length - 1)];
        String lName = lastNames[r.nextInt(lastNames.length - 1)];
        map.put("userName", fName + " " + lName);
        map.put("job", jobTitle[r.nextInt(jobTitle.length - 1)]);
        map.put("email", fName + "." + lName + "@server.com");
        map.put("employeeType", type[r.nextInt(type.length - 1)]);
        map.put("salary", new Float(salary[r.nextInt(salary.length - 1)]));
    
        data.add(map);
      }
      nextId = data.size() + 1;
    }
    
    private List fetchRecords(Map criteria, long start, long end) {
      int index = (int) start;
      List records = new ArrayList();
      if( end == -1) end = data.size();
      for (long i = start; i < end; i++) {
        records.add(data.get(index++));
        if (index >= data.size())
          break;
      }
      return records;
    }
    SimpleCustomDataSourceSample changes:
    Code:
    public Canvas getViewPanel() {
    
      DataSource customDS = DataSource.get("customDataSource_user");
    
      final ListGrid userList = new ListGrid();
      userList.setWidth(600);
      userList.setHeight(224);
      userList.setDataSource(customDS);
      userList.setCanEdit(true);
      userList.setCanRemoveRecords(true);
      userList.setLeaveScrollbarGap(false);
    
      userList.setAutoFetchData(true);
      userList.setFields(new ListGridField("userName"), new ListGridField(
          "job"), new ListGridField("email"), new ListGridField(
          "employeeType"), new ListGridField("salary"));
    
      userList.setDataFetchMode(FetchMode.PAGED);
      userList.setDataPageSize(100);
      AdvancedCriteria criteria = new AdvancedCriteria();
      criteria.setAttribute("fieldName", "salary");
      criteria.setAttribute( "operator", OperatorId.GREATER_OR_EQUAL_FIELD);
      criteria.setAttribute("value", Integer.valueOf(100));
      userList.setCriteria(criteria);
          
      IButton fetchButton = new IButton("ReFetch");
      fetchButton.setWidth(110);
      fetchButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
          Criteria c = userList.getCriteria();
          if (userList.willFetchData(c)) {
            GWT.log("Fetch will cause a server-side fetch");
            userList.fetchData(c);
          } else {
            GWT.log("Fetch will NOT cause a server-side fetch");
            userList.fetchData(c, new DSCallback() {
              @Override
              public void execute(DSResponse dsResponse, Object data,
                  DSRequest dsRequest) {
                GWT.log("Non-Fetching fetch callback!!!");
              }
            });
          }
        }
      });
    
      VLayout layout = new VLayout(15);
      layout.addMember(userList);
      layout.addMember(fetchButton);
    
      return layout;
    }
    Upon clicking "ReFetch" button a fetch is performed and the Development Mode tab shows:
    Code:
    09:51:37.710 [INFO] [showcase] - Fetch will NOT cause a server-side fetch
    09:51:38.090 [INFO] [showcase] - Non-Fetching fetch callback!!!

    Comment


      #3
      Thanks for the sample code. We see the issue and are investigating. Note for future reference, please use SC.logWarn() rather than GWT.log(), unless the bug you're reporting is specific to Dev Mode, so that the output is available in Production Mode.

      Comment


        #4
        Thanks and I will keep the SC.logWarn in mind.

        Comment


          #5
          The problem here is that you're not supplying the textMatchStyle to willFetchData() that's used by fetchData(). ListGrid.fetchData() uses by default the "exact" style, so your sample needs to be changed to:

          Code:
           if (userList.willFetchData(c, TextMatchStyle.EXACT)) {
          That should fix the problem. We'll improve our docs to make this requirement more obvious.

          BTW, we had to modify your sample code to ensure data is fetched properly when the ListGrid is scrolled:
          Code:
            public DSResponse executeFetch(DSRequest req) throws Exception {
                  long start = req.getStartRow();
                  long end = req.getEndRow();
                  List records = fetchRecords(req.getCriteria(), start, end);
                  DSResponse resp = new DSResponse(records);
                  resp.setTotalRows(data.size());
                  resp.setStartRow(start);
                  resp.setEndRow(start + records.size());
                  return resp;
              }
          Note the setStartRow()/setEndRow() changes.
          Last edited by Isomorphic; 8 Oct 2014, 22:08.

          Comment


            #6
            Thank you kindly. I will give it a try.

            Comment


              #7
              Making the suggested changes fixed the issue. Thanks.

              Comment

              Working...
              X