Announcement

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

  • #16
    It's best here to take a step back and explain what you're actually trying to do - our previous responses were based on what we thought you might be trying to do.

    Comment


    • #17
      Hi Isomorphic,

      First I would like to mention:
      No matter how many I have the fields and the criteria, I always get two criteria in the "setter".


      Click image for larger version  Name:	filter_test2.gif Views:	1 Size:	103.5 KB ID:	256600

      In my test case I get these two criteria:
      Code:
      {operator=and, criteria=[{operator=and, criteria=[{operator=and, criteria=[{operator=and, criteria=[{operator=and, criteria=[{operator=and, criteria=[{fieldName=commonName, operator=iContains, value=ara}, {fieldName=commonName, operator=iContains, value=cam}]}, {fieldName=scientificName, operator=iContains, value=cam}]}, {fieldName=scientificName, operator=iContains, value=dro}]}, {fieldName=scientificName, operator=iContains, value=dro}]}, {fieldName=information, operator=iContains, value=can}]}, {fieldName=information, operator=iContains, value=any}], $H=3}
      Code:
      {fieldName=information, operator=iContains, value=any}
      Why is that so?

      But it doesn't matter a lot because I've found a solution for it (it will work until you change something in that area).

      "fieldMap" for my test case contains next values:
      Code:
      {commonName=ara cam, scientificName=cam dro, information=can any}
      For the first field(commonName) in the filter editor, the following value should be displayed: ara cam.
      For the second field(scientificName) in the filter editor , the following value should be displayed: cam dro.
      For the third field(information) in the filter editor, the following value should be displayed: can any.

      I want my filter to have the same behaviour as a filter for the ListGrid after user triggers filtering.
      Only my filter in this case uses the iContains operator for each field and for each String entered, therefore it removes the duplicate values.

      Code:
      package com.smartgwt.sample.client;
      
      import java.util.ArrayList;
      import java.util.Arrays;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      import java.util.Set;
      
      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.FormItemCanEditCriterionPredicate;
      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");
                          commonNameLGF.setFilterEditorProperties(new FilterTextItem("commonName"));
      
                          ListGridField scientificNameLGF = new ListGridField("scientificName");
                          scientificNameLGF.setFilterEditorProperties(new FilterTextItem("scientificName"));
      
                          ListGridField informationLGF = new ListGridField("information");
                          informationLGF.setFilterEditorProperties(new FilterTextItem("information"));
      
                          setFields(commonNameLGF, scientificNameLGF, informationLGF);
                          setInitialSort(new SortSpecifier("commonName", SortDirection.ASCENDING));
                          fetchData();
                      }
      
                  };
                  addItem(lg);
              }
          }
      
          private class FilterTextItem extends TextItem {
              public FilterTextItem(final String name) {
                  super(name);
      
                  setCriterionGetter(new FormItemCriterionGetter() {
                      @Override
                      public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) {
                          return this.getCriterion(form, item);
                      }
      
                      @Override
                      public Criterion getCriterion(DynamicForm form, FormItem item) {
                          Object obj = form.getValue(name);
                          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(name, OperatorId.ICONTAINS, s[i]));
                              }
                              return finalCriteria;
                          }
                      }
                  });
                  setCriterionSetter(new FormItemCriterionSetter() {
                      @Override
                      public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                          Criterion[] allCriteria = criterion.getCriteria();
                          List<String> valueList = new ArrayList<String>();
                          for (Criterion c : allCriteria) {
                              String values = c.getValues().toString();
                              values = values.replaceAll("\\{", "").replaceAll("\\}", "").replaceAll("\\[", "").replaceAll("\\]", "");
                              values = values.replaceAll("operator=\\w+, ", "").replaceAll("criteria=", "").replaceAll("fieldName=", "");
                              values = values.replaceAll(", value", "");
                              valueList.addAll(Arrays.asList(values.split(",")));
                          }
                          Map<String, String> fieldMap = new HashMap<String, String>();
                          for (String s : valueList) {
                              String fieldName = s.replaceAll(" {0,1}(.*)=.*", "$1");
                              String value = s.replaceAll(".*=(.*)", "$1");
                              if (value != null && value.contains(" "))
                                  value.replaceAll(" ", "");
                              if (fieldMap.containsKey(fieldName)) {
                                  String oldValue = fieldMap.get(fieldName);
                                  if (!oldValue.contains(value))
                                      fieldMap.put(fieldName, oldValue + " " + value);
                              } else
                                  fieldMap.put(fieldName, value);
                          }
      
                          Set<String> fieldName = fieldMap.keySet();
                          // Set value for each field somehow???
                          for (String s : fieldName)
                              item.setAttribute(s, fieldMap.get(s));
                      }
                  });
                  setCanEditCriterionPredicate(new FormItemCanEditCriterionPredicate() {
                      @Override
                      public boolean canEditCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                          return true;
                      }
                  });
      
              }
          }
      }
      Best regards
      Pavo
      Last edited by pavo123; 24th Jan 2019, 01:03.

      Comment


      • #18
        It sounds like, since your criteria are for multiple fields, you just need to ensure that your canEditCriterion() implementation only returns true for criteria that apply to the field in question.

        Does that fix your problem?

        Comment


        • #19
          Hi Isomorphic,

          yes it is! But I think I've found a bug in this area.

          Click image for larger version  Name:	filter_test7.gif Views:	1 Size:	107.3 KB ID:	256631

          In "getter", after I trigers filtering second time, "form.getValue(name)" is null and "item.getValue()" is not null!

          Code:
          package com.smartgwt.sample.client;
          
          import java.util.ArrayList;
          import java.util.Arrays;
          import java.util.HashMap;
          import java.util.List;
          import java.util.Map;
          
          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.ResultSet;
          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.FormItemCanEditCriterionPredicate;
          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");
          
          ResultSet rsProperties = new ResultSet();
          rsProperties.setUseClientFiltering(false);
          setDataProperties(rsProperties);
          
          ListGridField commonNameLGF = new ListGridField("commonName");
          commonNameLGF.setFilterEditorProperties(new FilterTextItem("commonName"));
          
          ListGridField scientificNameLGF = new ListGridField("scientificName");
          scientificNameLGF.setFilterEditorProperties(new FilterTextItem("scientificName"));
          
          ListGridField informationLGF = new ListGridField("information");
          informationLGF.setFilterEditorProperties(new FilterTextItem("information"));
          
          setFields(commonNameLGF, scientificNameLGF, informationLGF);
          setInitialSort(new SortSpecifier("commonName", SortDirection.ASCENDING));
          fetchData();
          }
          
          };
          addItem(lg);
          }
          }
          
          private class FilterTextItem extends TextItem {
          public FilterTextItem(final String name) {
          super(name);
          
          setCriterionGetter(new FormItemCriterionGetter() {
          @Override
          public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) {
          return this.getCriterion(form, item);
          }
          
          @Override
          public Criterion getCriterion(DynamicForm form, FormItem item) {
          Object objDFField = form.getValue(name);
          if (objDFField == null) {
          // SC.logWarn("DF-Field: " + name + ". Value is null");
          Object objFormItem = item.getValue();
          if (objFormItem == null) {
          SC.logWarn("FormItem: " + name + ". Value is null and Field is also null, returning null. OK.");
          return null;
          }
          if (objDFField == null && objFormItem != null) {
          SC.logWarn("FormItem: " + name + ". Value is: " + objFormItem.toString() + " and DF-Field value is null. SHOULD NOT HAPPEN.");
          return null;
          }
          }
          String value = String.valueOf(objDFField);
          
          String[] s = value.split(" ");
          AdvancedCriteria finalCriteria = new AdvancedCriteria(OperatorId.AND);
          for (int i = 0; i < s.length; i++) {
          finalCriteria.addCriteria(new Criterion(name, OperatorId.ICONTAINS, s[i]));
          }
          // SC.logWarn("Field: " + name + ". Return final criteria: " + finalCriteria.getValues());
          return finalCriteria;
          }
          });
          setCriterionSetter(new FormItemCriterionSetter() {
          @Override
          public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) {
          Criterion[] allCriteria = criterion.getCriteria();
          List<String> valueList = new ArrayList<String>();
          for (Criterion c : allCriteria) {
          String values = c.getValues().toString();
          values = values.replaceAll("\\{", "").replaceAll("\\}", "").replaceAll("\\[", "").replaceAll("\\]", "");
          values = values.replaceAll("operator=\\w+, ", "").replaceAll("criteria=", "").replaceAll("fieldName=", "");
          values = values.replaceAll(", value", "");
          valueList.addAll(Arrays.asList(values.split(",")));
          }
          Map<String, String> fieldMap = new HashMap<String, String>();
          for (String s : valueList) {
          String fieldName = s.replaceAll(" {0,1}(.*)=.*", "$1");
          String value = s.replaceAll(".*=(.*)", "$1");
          if (value != null && value.contains(" "))
          value.replaceAll(" ", "");
          if (fieldMap.containsKey(fieldName)) {
          String oldValue = fieldMap.get(fieldName);
          if (!oldValue.contains(value))
          fieldMap.put(fieldName, oldValue + " " + value);
          } else
          fieldMap.put(fieldName, value);
          }
          
          if (fieldMap.containsKey(item.getFieldName())) {
          // SC.logWarn("Sets " + item.getFieldName() + " value: " + fieldMap.get(item.getFieldName()));
          form.setValue(item.getFieldName(), fieldMap.get(item.getFieldName()));
          }
          }
          });
          setCanEditCriterionPredicate(new FormItemCanEditCriterionPredicate() {
          @Override
          public boolean canEditCriterion(DynamicForm form, FormItem item, Criterion criterion) {
          List<String> valueList = new ArrayList<String>();
          @SuppressWarnings("unchecked")
          String values = ((Map<String, String>) criterion.getValues()).toString();
          values = values.replaceAll("\\{", "").replaceAll("\\}", "").replaceAll("\\[", "").replaceAll("\\]", "");
          values = values.replaceAll("operator=\\w+, ", "").replaceAll("criteria=", "").replaceAll("fieldName=", "");
          values = values.replaceAll(", value", "");
          valueList.addAll(Arrays.asList(values.split(",")));
          
          Map<String, String> fieldMap = new HashMap<String, String>();
          for (String s : valueList) {
          String fieldName = s.replaceAll(" {0,1}(.*)=.*", "$1");
          String value = s.replaceAll(".*=(.*)", "$1");
          if (value != null && value.contains(" "))
          value.replaceAll(" ", "");
          if (fieldMap.containsKey(fieldName)) {
          String oldValue = fieldMap.get(fieldName);
          if (!oldValue.contains(value))
          fieldMap.put(fieldName, oldValue + " " + value);
          } else
          fieldMap.put(fieldName, value);
          }
          
          if (fieldMap.containsKey(item.getFieldName())) {
          // SC.logWarn("canEditCriterion() returns TRUE for " + item.getFieldName() + " and criterion " + fieldMap.toString());
          return true;
          } else {
          // SC.logWarn("canEditCriterion() returns FALSE for " + item.getFieldName() + " and criterion " + fieldMap.toString());
          return false;
          }
          }
          });
          
          }
          }
          }
          Best regards
          Pavo

          Comment


          • #20
            We've made a DynamicForm change which effectively compresses or flattens the criteria received in this case - as of tomorrow's builds, this test-case will work with the following example code:

            Code:
                        setCriterionSetter(new FormItemCriterionSetter() {
                            @Override
                            public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                                Criterion[] criteria = criterion.getCriteria();
                                String result = "";
                                for (Criterion c : criteria) {
                                    String value = c.getValueAsString();
                                    if (value != null && value != "") {
                                        if (result.length() > 0) result += " ";
                                        result += value;
                                    }
                                }
                                item.setValue(result);
                            }
                        });
                        setCanEditCriterionPredicate(new FormItemCanEditCriterionPredicate() {
                            @Override
                            public boolean canEditCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                                String itemName = item.getName();
                                if (criterion.getFieldName() == itemName) {
                                    return true;
                                }
                                Criterion[] criteria = criterion.getCriteria();
                                for (Criterion crit : criteria) {
                                    if (crit.getFieldName() != itemName) {
                                        return false;
                                    }
                                }
                                return true;
                            }
                        });

            Comment


            • #21
              Hi Isomorphic,

              this will certainly simplify my code, great!

              But I also reported a bug in post #19, so you can look at it if you're interested. If I use always "item.getValue()" and never "form.getValue(name)", then the problem is solved. But I still think this is a bug.

              Best regards
              Pavo

              Comment


              • #22
                Btw. in your post #20,

                IMHO this line of code
                Code:
                if (criterion.getFieldName() == itemName) {
                should be replaced with this one:
                Code:
                if (criterion.getFieldName() != null && criterion.getFieldName().equals(itemName)) {
                Now canEditCriterion() always returns true.

                Comment


                • #23
                  Hi Isomorphic,

                  please see this issue that might be related to changes in this area.

                  Thank you & Best regards
                  Blama

                  Comment


                  • #24
                    Hi Isomorphic,

                    please take a look at this test case. I've found a new bug.

                    Click image for larger version

Name:	filter_bug.gif
Views:	1
Size:	86.4 KB
ID:	256955

                    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.ResultSet;
                    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.FormItemCanEditCriterionPredicate;
                    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");
                    
                                        ResultSet rsProperties = new ResultSet();
                                        rsProperties.setUseClientFiltering(false);
                                        setDataProperties(rsProperties);
                    
                                        ListGridField commonNameLGF = new ListGridField("commonName");
                                        commonNameLGF.setFilterEditorProperties(new FilterTextItem("commonName"));
                    
                                        ListGridField scientificNameLGF = new ListGridField("scientificName");
                                        scientificNameLGF.setFilterEditorProperties(new FilterTextItem("scientificName"));
                    
                                        ListGridField informationLGF = new ListGridField("information");
                                        informationLGF.setFilterEditorProperties(new FilterTextItem("information"));
                    
                                        setFields(commonNameLGF, scientificNameLGF, informationLGF);
                                        setInitialSort(new SortSpecifier("commonName", SortDirection.ASCENDING));
                                        fetchData();
                                    }
                    
                                };
                                addItem(lg);
                            }
                        }
                    
                        private class FilterTextItem extends TextItem {
                            public FilterTextItem(final String name) {
                                super(name);
                    
                                setCriterionGetter(new FormItemCriterionGetter() {
                                    @Override
                                    public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) {
                                        return this.getCriterion(form, item);
                                    }
                    
                                    @Override
                                    public Criterion getCriterion(DynamicForm form, FormItem item) {
                                        Object objFormItem = item.getValue();
                                        if (objFormItem == null)
                                            return null;
                    
                                        String value = String.valueOf(objFormItem);
                                        String[] s = value.split(" ");
                                        AdvancedCriteria finalCriteria = new AdvancedCriteria(OperatorId.AND);
                                        for (int i = 0; i < s.length; i++) {
                                            finalCriteria.addCriteria(new Criterion(name, OperatorId.ICONTAINS, s[i]));
                                        }
                                        return finalCriteria;
                                    }
                                });
                                setCriterionSetter(new FormItemCriterionSetter() {
                                    @Override
                                    public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                                        Criterion[] criteria = criterion.getCriteria();
                                        String result = "";
                                        for (Criterion c : criteria) {
                                            String value = c.getValueAsString();
                                            if (value != null && value != "") {
                                                if (result.length() > 0)
                                                    result += " ";
                                                result += value;
                                            }
                                        }
                                        item.setValue(result);
                                    }
                                });
                                setCanEditCriterionPredicate(new FormItemCanEditCriterionPredicate() {
                                    @Override
                                    public boolean canEditCriterion(DynamicForm form, FormItem item, Criterion criterion) {
                                        String itemName = item.getName();
                                        if (itemName != null && criterion.getFieldName() != null && criterion.getFieldName().equals(itemName)) {
                                            return true;
                                        }
                                        Criterion[] criteria = criterion.getCriteria();
                                        for (Criterion crit : criteria) {
                                            if (itemName != null && crit.getFieldName() != null && !(crit.getFieldName().equals(itemName))) {
                                                return false;
                                            }
                                        }
                                        return true;
                                    }
                                });
                            }
                        }
                    }
                    Best regards
                    Pavo

                    Comment


                    • #25
                      This isn't a bug - your canEditCriterion() implementation returns true if the crit and item names are the same, but doesn't return false if they're different. Since your method returns true by default, you can just change your first condition to something like this:

                      Code:
                      String itemName = item.getName();
                      if (itemName != null) {
                          if (criterion.getFieldName() != null && !criterion.getFieldName().equals(itemName)) {
                              return false;
                          }
                      }
                      Last edited by Isomorphic; Yesterday, 23:43.

                      Comment


                      • #26
                        Hi Isomorphic,

                        it works if I enter 2 or more words, but if I just enter one word then it doesn't work.

                        Best regards
                        Pavo

                        Comment


                        • #27
                          Right - that's because your setCriterion() implementation doesn't deal with being passed a single criterion (which is what an "and" crit with one subcrit is flattened to) - just add this at the top of your setCriterion():

                          Code:
                                              if (criterion.getFieldName() != null) {
                                                  result = criterion.getValueAsString();
                                              } else {
                                                  ... loop over sub-criteria
                                              }

                          Comment


                          • #28
                            Exactly. Thank you very much!

                            Comment

                            Working...
                            X