Announcement

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

  • FormItemCriterionGetter and FormItemCriterionSetter

    Hi Isomorphic,

    I have a strange problems with FormItemCriterionGetter and FormItemCriterionSetter.
    Please take a look at this test case.
    I put breakpoint on every line which start with "SC.logWarn()". No breakpoint is hit.

    v11.1p_2018-12-03/PowerEdition Deployment (built 2018-12-03)
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criterion;
    import com.smartgwt.client.data.SortSpecifier;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.types.SortDirection;
    import com.smartgwt.client.types.TextMatchStyle;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.FormItemCriterionGetter;
    import com.smartgwt.client.widgets.form.FormItemCriterionSetter;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS extends VLayout implements EntryPoint {
        private IButton recreateBtn;
    
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            setWidth100();
            setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    new MyWindow().show();
                }
            });
            addMember(recreateBtn);
            new MyWindow().show();
            draw();
        }
    
        private class MyWindow extends Window {
            public MyWindow() {
                setWidth(600);
                setHeight(300);
                setMembersMargin(0);
                setModalMaskOpacity(70);
                setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                final ListGrid lg = new ListGrid() {
                    {
                        setShowFilterEditor(true);
                        setDataSource("animals");
    
                        ListGridField commonNameLGF = new ListGridField("commonName");
                        commonNameLGF.setCanFilter(false);
                        ListGridField informationLGF = new ListGridField("information");
                        informationLGF.setCanFilter(true);
                        informationLGF.setFilterEditorProperties(new TextItem("information") {
                            {
                                setCriterionGetter(new FormItemCriterionGetter() {
                                    @Override
                                    public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) {
                                        SC.logWarn("getCriterion 1 never called!");
                                        return this.getCriterion(form, item);
                                    }
    
                                    @Override
                                    public Criterion getCriterion(DynamicForm form, FormItem item) {
                                        SC.logWarn("getCriterion 2 never called!");
                                        Object obj = form.getValue("information");
                                        if (obj == null) {
                                            return null;
                                        } else {
                                            String value = String.valueOf(obj);
                                            String[] s = value.split(" ");
                                            AdvancedCriteria finalCriteria = new AdvancedCriteria(OperatorId.AND);
                                            for (int i = 0; i < s.length; i++) {
                                                finalCriteria.addCriteria(new Criterion("information", OperatorId.ICONTAINS, s[i]));
                                            }
                                            return finalCriteria;
                                        }
                                    }
                                });
    
                                setCriterionSetter(new FormItemCriterionSetter() {
                                    @Override
                                    public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                                        SC.logWarn("setCriterion never called!");
                                    }
                                });
    
                            }
    
                            @Override
                            public Boolean hasAdvancedCriteria() {
                                SC.logWarn("hasAdvancedCriteria never called!");
                                return true;
                            }
                        });
    
                        setFields(commonNameLGF, informationLGF);
                        setInitialSort(new SortSpecifier("commonName", SortDirection.ASCENDING));
                        fetchData();
                    }
    
                };
                addItem(lg);
            }
        }
    }
    This topic is probably related to my problem Bug: CriteriaEditing broken?

    Best regards
    Pavo
    Last edited by pavo123; 8th Jan 2019, 02:51.

  • #2
    Youíre expecting a constructor to be called on the properties object you supplied. It doesnít work that way, itís just properties. Configure it without trying to use a constructor and it will work.

    Note thereís a central discussion of how properties objects work in the docs.

    Comment


    • #3
      I really don't know how should I do that. How to configure it without trying to use a constructor? Can you please give me some example?

      Strange thing is that in my app, "setCriterionGetter" works as excpected (configured in the same way as in this test case) and "setCriterionSetter" is never called.
      So I tried to reproduce that problem but stuck with this problem above. Little confuzing for me.
      Last edited by pavo123; 8th Jan 2019, 06:07.

      Comment


      • #4
        ??

        You are creating an instance of TextItem. Simply call the methods on it.

        Comment


        • #5
          Hi Isomorphic,

          did you mean in this way? Nothing changes.

          Code:
                      final ListGrid lg = new ListGrid() {
                          {
                              setShowFilterEditor(true);
                              setDataSource("animals");
          
                              ListGridField commonNameLGF = new ListGridField("commonName");
                              ListGridField informationLGF = new ListGridField("information");
                              TextItem ti = new TextItem();
                              ti.setCriterionGetter(new FormItemCriterionGetter() {
          
                                  @Override
                                  public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) {
                                      SC.logWarn("Never called!");
                                      return null;
                                  }
          
                                  @Override
                                  public Criterion getCriterion(DynamicForm form, FormItem item) {
                                      SC.logWarn("Never called!");
                                      return null;
                                  }
                              });
                              ti.setCriterionSetter(new FormItemCriterionSetter() {
                                  @Override
                                  public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                                      SC.logWarn("Never called!");
          
                                  }
                              });
          
                              informationLGF.setFilterEditorProperties(ti);
                              setFields(commonNameLGF, informationLGF);
                              setInitialSort(new SortSpecifier("commonName", SortDirection.ASCENDING));
                              fetchData();
                          }
          
                      };
          Best regards
          Pavo

          Comment


          • #6
            This code doesnít set any criteria, so one would not expected the setter to be called yet. The getter would be called after the user types something and triggers filtering.

            Comment


            • #7
              Hi Isomorphic,

              in my test case, the getter is not called after the user types something and triggers filtering.

              v11.1p_2019-01-08/PowerEdition Deployment (built 2019-01-08)

              Code:
              package com.smartgwt.sample.client;
              
              import com.google.gwt.core.client.EntryPoint;
              import com.google.gwt.core.client.GWT;
              import com.smartgwt.client.Version;
              import com.smartgwt.client.bean.BeanFactory;
              import com.smartgwt.client.core.KeyIdentifier;
              import com.smartgwt.client.data.AdvancedCriteria;
              import com.smartgwt.client.data.Criterion;
              import com.smartgwt.client.data.SortSpecifier;
              import com.smartgwt.client.types.OperatorId;
              import com.smartgwt.client.types.SortDirection;
              import com.smartgwt.client.types.TextMatchStyle;
              import com.smartgwt.client.util.Page;
              import com.smartgwt.client.util.PageKeyHandler;
              import com.smartgwt.client.util.SC;
              import com.smartgwt.client.widgets.IButton;
              import com.smartgwt.client.widgets.Window;
              import com.smartgwt.client.widgets.events.ClickEvent;
              import com.smartgwt.client.widgets.events.ClickHandler;
              import com.smartgwt.client.widgets.form.DynamicForm;
              import com.smartgwt.client.widgets.form.FormItemCriterionGetter;
              import com.smartgwt.client.widgets.form.FormItemCriterionSetter;
              import com.smartgwt.client.widgets.form.fields.FormItem;
              import com.smartgwt.client.widgets.form.fields.TextItem;
              import com.smartgwt.client.widgets.grid.ListGrid;
              import com.smartgwt.client.widgets.grid.ListGridField;
              import com.smartgwt.client.widgets.layout.VLayout;
              
              public class BuiltInDS extends VLayout implements EntryPoint {
                  private IButton recreateBtn;
              
                  public void onModuleLoad() {
                      GWT.create(BeanFactory.FormItemMetaFactory.class);
              
                      KeyIdentifier debugKey = new KeyIdentifier();
                      debugKey.setCtrlKey(true);
                      debugKey.setKeyName("D");
              
                      Page.registerKey(debugKey, new PageKeyHandler() {
                          public void execute(String keyName) {
                              SC.showConsole();
                          }
                      });
              
                      setWidth100();
                      setHeight100();
              
                      recreateBtn = new IButton("Recreate");
                      recreateBtn.addClickHandler(new ClickHandler() {
                          @Override
                          public void onClick(ClickEvent event) {
                              new MyWindow().show();
                          }
                      });
                      addMember(recreateBtn);
                      new MyWindow().show();
                      draw();
                  }
              
                  private class MyWindow extends Window {
                      public MyWindow() {
                          setWidth(600);
                          setHeight(300);
                          setMembersMargin(0);
                          setModalMaskOpacity(70);
                          setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                          setShowMinimizeButton(false);
                          setIsModal(true);
                          setShowModalMask(true);
                          centerInPage();
              
                          final ListGrid lg = new ListGrid() {
                              {
                                  setShowFilterEditor(true);
                                  setDataSource("animals");
              
                                  ListGridField commonNameLGF = new ListGridField("commonName");
                                  ListGridField informationLGF = new ListGridField("information");
                                  TextItem ti = new TextItem();
                                  ti.setCriterionGetter(new FormItemCriterionGetter() {
              
                                      @Override
                                      public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) {
                                          SC.logWarn("Never called!");
              
                                          return this.getCriterion(form, item);
                                      }
              
                                      @Override
                                      public Criterion getCriterion(DynamicForm form, FormItem item) {
                                          SC.logWarn("Never called!");
              
                                          AdvancedCriteria finalCriteria = new AdvancedCriteria(OperatorId.AND);
                                          finalCriteria.addCriteria(new Criterion("information", OperatorId.ICONTAINS, "is"));
                                          finalCriteria.addCriteria(new Criterion("information", OperatorId.ICONTAINS, "now"));
                                          return finalCriteria;
                                      }
                                  });
                                  ti.setCriterionSetter(new FormItemCriterionSetter() {
                                      @Override
                                      public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                                          SC.logWarn("Never called!");
              
                                      }
                                  });
              
                                  informationLGF.setFilterEditorProperties(ti);
                                  setFields(commonNameLGF, informationLGF);
                                  setInitialSort(new SortSpecifier("commonName", SortDirection.ASCENDING));
                                  fetchData();
                              }
              
                          };
                          addItem(lg);
                      }
                  }
              }
              Best regards
              Pavo

              Comment


              • #8
                The problem here is that getCriterion() is not called when the grid's criterion is simple.

                You can force the grid to produce AdvancedCriteria either by setting a filterOperator on the field, or by setting grid.allowFilterExpressions: true.

                We're looking at adding a new attribute to directly force a grid to produce AdvancedCriteria and will update here as and when we have more information.

                Comment


                • #9
                  By way of a followup on this issue - our problem description was correct and the solutions offered would be expected to work, but it turns out that there was indeed a bug here.

                  Some JSNI logic intended to ensure that a custom getCriterion() implementation always runs was misbehaving - we've fixed that for builds dated January 16 and later.

                  We've also added ListGrid (and FormItem) .useAdvancedCriteria to enforce advancedCriteria in all cases, meaning filterItem.getCriterion() will always run (whether you customized it or not).

                  Comment

                  Working...
                  X