Announcement

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

    Problem updating application from 4.0p to 5.0p

    Hi,

    We updated our application from 4.0p to latest 5.0p nightly (2015-10-31) and encountered the following error right at the startup of the application:

    com.google.gwt.core.client.JavaScriptException: (ReferenceError) : criteria is not defined
    at Unknown.fetchData_1_g...

    Our app initializes some of our DataSources when starting up by calling OurDataSource.getInstance().fetchData(). We tracked down the problem to the method DataSource.java/fetchData method of 5.0p:

    public native void fetchData() /*-{
    var self = this.@com.smartgwt.client.core.BaseClass::getOrCreateJsObj()();
    if(@com.smartgwt.client.data.Criterion::instanceOf(Ljava/lang/Object;)(criteria)) {
    @com.smartgwt.client.util.JSOHelper::setAttribute(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;Ljava/lang/String;)(criteria.@com.smartgwt.client.data.Criterion::getJsObj()(),"_constructor","AdvancedCriteria");
    }
    self.fetchData();
    }-*/;

    The application fails on the second line of this method because "criteria" is not set. 4.0p variant of this method does not have this line. Before debugging any furher (our application is quite complex) - any ideas what might be going on here ? Thanks!

    #2
    The problem here looks to be that this method should not exist, because it doesn't make sense to call DataSource.fetchData() without a callback (the returned data would go nowhere). For what purpose does your application call this method?

    Comment


      #3
      Ok, makes sense.

      The DataSource in question seems to be configured to "cacheAllData" so the call here is probably just a prefetch and fill this cache. We can probably get rid of this in our code or atleast replace it with a working variant. Maybe hiding this method (or fixing it with a check against criteria if feasible) might be in question anyways. Thanks for the help.

      Comment


        #4
        Yes, we'll most likely be fixing the method but also deprecating it and pointing out that it would only make sense to call in a scenario like yours, and then only with a callback.

        Comment


          #5
          I can confirm it works if I pass a simple criteria to the fetchData(criteria) method.

          We encountered an another problem with 5.0p in our testing though. We have ListGrid's with filter editors configured to filter local data. We have some fields which are configured from datasource to show a different record attribute value as follows:

          ListGridField f1 = new ListGridField("f1");
          f1.setDisplayField("anotherField");
          ...

          When filtering with these fields, the filter editor for these fields works as expected: it renders a combobox with possible choices of items in them. When we select a value it works correctly. But, when we clear the criteria from these fields and enter a criteria value to some _other_ field, these "displayField set fields" generate incorrect blank criteria. What happens is that the grid filters out all records and when inspecting the current criteria from the grid by calling getFilterEditorCriteria, the criteria gets appended with

          { fieldName: "f1", value: "<span aria-hidden="true">&nbsp;</span>", fieldName: "f1", value: "<span aria-hidden="true">&nbsp;</span>", ... }

          The grid gets stuck in a limbo where entering anything to the filter editor of other fields just add and add this incorrect (advanced) criteria to the editor. When inspecting the DOM, this "<span aria-hidden="true">&nbsp;</span>" seems to be the blank value of the combobox selector widget. Is there some weird situation where the filter editor might pick this html content from the filter editor widget incorrectly ?

          We tried constructing a simple test case for this with little success yet, but the problem persists in our real application even when we try to strip out all pecularities from the initialization of the components.

          Comment


            #6
            An issue along these lines existed for a while in older 5.0p builds, but was corrected.

            Are you sure you're using the latest patched build? You should double-check using the approach explained in the FAQ.

            Comment


              #7
              It seems to be the latest one. By looking at the developer console:

              v10.0p_2015-10-31/LGPL Development Only (built 2015-10-31)

              Comment


                #8
                OK. Having already fixed the only known case of this, we don't really have a theory for how this could still occur - hopefully you will be able to create a test case that replicates the behavior from your application.

                Comment


                  #9
                  We think we got a test case to trigger the bug. It seems to happen when for any reason the filtering has advance criteria set (for example the ListGrid itself has AdvancedCriteria set or, some item produces AdvancedCriteria). When so, the criteria gets appended with incorrect criteria for the displayField set. Please see the attached test case.

                  When we debugged this we noticed SelectItem has emptyDisplayValue set as "&nbsp;" and by the look of it, it might be that the form in the filterEditor trips and stores this value as a set value sometimes.

                  How to produce:

                  1. Enter some criteria to grid field's "f2" filter
                  2. Observe, that the filtering of the grid breaks down
                  3. Click "show criteria" to print out the current filter criteria
                  4. Rinse & repeat 1-3
                  Code:
                      public ListGridRecord getRecord(int i) {
                          ListGridRecord r = new ListGridRecord();
                          r.setAttribute("f1", i);
                          r.setAttribute("f2", "record " + i + " f2");
                          r.setAttribute("f3", "record " + i + " f3");
                          r.setAttribute("f4", "record " + i + " f4");
                          return r;
                      }
                  
                      public void doOnModuleLoad() {
                          SC.showConsole();
                  
                          viewport = new VLayout();
                          viewport.setWidth100();
                          viewport.setHeight100();
                          viewport.setOverflow(Overflow.HIDDEN);
                  
                          DataSource ds = new DataSource();
                          ds.setID("myDS");
                          DataSourceIntegerField f1 = new DataSourceIntegerField("f1");
                          f1.setPrimaryKey(true);
                          DataSourceTextField f2 = new DataSourceTextField("f2");
                          DataSourceTextField f3 = new DataSourceTextField("f3");
                          DataSourceTextField f4 = new DataSourceTextField("f4");
                          ds.setFields(f1, f2, f3, f4);
                  
                          ListGridRecord[] data = new ListGridRecord[]{
                                  getRecord(1), getRecord(2), getRecord(3), getRecord(4)
                          };
                  
                          ds.setTestData(data);
                          ds.setClientOnly(true);
                  
                          final ListGrid g = new ListGrid();
                          g.setDataSource(ds);
                          g.setWidth(400);
                          g.setHeight(400);
                  
                          g.setAutoFetchData(true);
                          g.setShowFilterEditor(true);
                          g.setFilterOnKeypress(true);
                  
                          AdvancedCriteria ac = new AdvancedCriteria();
                          g.setCriteria(ac);
                  
                          ListGridField gf1 = new ListGridField("f1");
                          gf1.setDisplayField("f4");
                          ListGridField gf2 = new ListGridField("f2");
                          ListGridField gf3 = new ListGridField("f3");
                  
                          g.setFields(gf1, gf2, gf3);
                  
                          viewport.addMember(g);
                  
                          Button b = new Button("show criteria");
                          b.addClickHandler(new ClickHandler() {
                              @Override
                              public void onClick(ClickEvent event) {
                                  Criteria c = g.getFilterEditorCriteria();
                                  SC.say("" + (c != null ? c.getValues() : "no criteria"));
                              }
                          });
                          viewport.addMember(b);
                  
                          viewport.draw();
                      }
                  Last edited by markok; 6 Nov 2015, 03:52.

                  Comment


                    #10
                    Hi, any news on this ? Have you had time to confirm this issue and/or is there probably a workaround for this ?

                    Comment


                      #11
                      This is still being worked on. A simple workaround is to simply remove the spurious criteria, but you'll most likely have a real fix in the next few days.

                      In the meantime, the zero-argument fetchData() signature has been deprecated with docs explaining why it doesn't make sense to call.

                      Comment


                        #12
                        In the end, we don't see a bug here. The problem seems to be that your code doesn't set the approriate properties for this to work correctly.

                        Two things:

                        1) your ListGridField needs valueField to be set, as well as displayField
                        2) you need to use field.setEditorProperties() to pass in a SelectItem instance on which you've called setCriteriaField("f1") - that is, the name of the valueField

                        From there, you would probably also want to call setOperator(OperatorID.EQUALS) on the editorProperties, unless you really *do* want to do an iContains comparison. Note that calling setOperator() in this way would mean the grid would always return advancedCriteria, without you having to set it up in advance (which technique only works once anyway).

                        Comment


                          #13
                          Thanks for the tips but we cannot get this working. Could you please elaborate a bit ?

                          Code:
                                  ListGridField gf1 = new ListGridField("f1");
                                  gf1.setDisplayField("f4");
                          
                                  // this should fix the grid filtering ?
                                  gf1.setValueField("f1");
                                  SelectItem si = new SelectItem();
                                  si.setCriteriaField("f1");
                                  gf1.setFilterEditorProperties(si);
                                  // /this should fix the grid filtering ?
                          
                                  ListGridField gf2 = new ListGridField("f2");
                          What exactly would you change in the test case sent earlier to make it work ?

                          Just to note, our primary application where this issue manifests is much more complex one than the simple test case we sent you. We actually have some custom search operators set up in our grid which make the grid generate advanced criteria. All this works fine in 4.0p branch we're currently using. We tracked down the 5.0p issue to the presence of advancedcriteria and the issue seems to popup as easily by just setting the grid with (in this test case empty) advancedcriteria.
                          Last edited by markok; 11 Nov 2015, 06:07.

                          Comment


                            #14
                            We just changed the following block:

                            Code:
                                    // don't do this - it doesn't achieve anything by itelf
                                    //AdvancedCriteria ac = new AdvancedCriteria();
                                    //g.setCriteria(ac);
                            
                                    ListGridField gf1 = new ListGridField("f1");
                                    gf1.setDisplayField("f4");
                                    // needs valueField to be set as well - we'll make changes to default it from field.name at some future time
                                    gf1.setValueField("f1");
                                    
                                    SelectItem fItem = new SelectItem();
                                    fItem.setCriteriaField("f1");
                                    // f1 is the PK and the source of a list of distinct items, in a select, not a combo, so an equals operator makes more sense than iContains
                                    // - not necessary, but with it, the grid always produces advancedCriteria, if that's what you were trying to achieve with the empty advancedCriteria earlier in this code
                                    fItem.setOperator(OperatorId.EQUALS);
                                    gf1.setEditorProperties(fItem);

                            Comment


                              #15
                              Ok, well that seems to fix it in this test case. In our real application we are calling setFilterOperator method to set different filter operators for different fields. This breaks it down again (see the code below).

                              It seems to be fixed though by the workaround you use (setting the operator to EditorProperties of the field). But, is it intentional that the setFilterOperator method does not work anymore as it used to work in earlier releases ?

                              Code:
                                  public void doOnModuleLoad() {
                                      SC.showConsole();
                              
                                      viewport = new VLayout();
                                      viewport.setWidth100();
                                      viewport.setHeight100();
                                      viewport.setOverflow(Overflow.HIDDEN);
                              
                                      DataSource ds = new DataSource();
                                      ds.setID("myDS");
                                      DataSourceIntegerField f1 = new DataSourceIntegerField("f1");
                                      f1.setPrimaryKey(true);
                                      DataSourceTextField f2 = new DataSourceTextField("f2");
                                      DataSourceTextField f3 = new DataSourceTextField("f3");
                                      DataSourceTextField f4 = new DataSourceTextField("f4");
                                      ds.setFields(f1, f2, f3, f4);
                              
                                      ListGridRecord[] data = new ListGridRecord[]{
                                              getRecord(1), getRecord(2), getRecord(3), getRecord(4)
                                      };
                              
                                      ds.setTestData(data);
                                      ds.setClientOnly(true);
                              
                                      final ListGrid g = new ListGrid();
                                      g.setDataSource(ds);
                                      g.setWidth(400);
                                      g.setHeight(400);
                                      g.setAutoFetchData(true);
                                      g.setShowFilterEditor(true);
                                      g.setFilterOnKeypress(true);
                              
                                      ListGridField gf1 = new ListGridField("f1");
                                      gf1.setDisplayField("f4");
                              
                                      // this should fix the grid filtering ?
                                      gf1.setValueField("f1");
                                      SelectItem fItem = new SelectItem();
                                      fItem.setCriteriaField("f1");
                                      fItem.setOperator(OperatorId.EQUALS);
                                      gf1.setEditorProperties(fItem);
                                      // /this should fix the grid filtering ?
                              
                                      ListGridField gf2 = new ListGridField("f2");
                                      // .. and this breaks it again
                                      gf2.setFilterOperator(OperatorId.ICONTAINS);
                                      ListGridField gf3 = new ListGridField("f3");
                              
                                      g.setFields(gf1, gf2, gf3);
                              
                                      viewport.addMember(g);
                              
                                      Button b = new Button("show criteria");
                                      b.addClickHandler(new ClickHandler() {
                                          @Override
                                          public void onClick(ClickEvent event) {
                                              Criteria c = g.getFilterEditorCriteria();
                                              SC.say("" + (c != null ? c.getValues() : "no criteria"));
                                          }
                                      });
                                      viewport.addMember(b);
                              
                                      viewport.draw();
                                  }

                              Comment

                              Working...
                              X