Announcement

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

    Bugs in Smartgwt Dropdown Tree

    Hello,
    I found 2 bugs in Smartgwt Dropdown Tree.
    1) SelectItem. fetchData() causes JavaScriptException (TypeError): data._invalidateCache is not a function.
    As I understand the _invalidateCache function is missing in ResultTree.
    2) When setMultiple(true) and setMultipleAppearance(MultipleAppearance.PICKLIST) are set for Dropdown Tree, select item value is not updated after selection change. I found workaround but this really should be fixed.
    Smart GWT version 12.0

    Test code:
    package test2.client;

    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.types.MultipleAppearance;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ButtonItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;

    /**
    * Entry point classes define <code>onModuleLoad()</code>.
    */
    public class TestTreeSelect2 implements EntryPoint {

    private int counter = 10;

    /**
    * This is the entry point method.
    */
    public void onModuleLoad() {
    DataSource ds = new TestDS();

    final DynamicForm form = new DynamicForm();
    form.setWidth(500);

    ListGridField nameField = new ListGridField("name");
    ListGridField emailField = new ListGridField("id");

    ListGrid pickListProperties = new ListGrid();
    pickListProperties.setAutoFitFieldWidths(true);

    SelectItem item = new SelectItem("manager");
    item.setTitle("Choose Manager");
    item.setOptionDataSource(ds);
    item.setDataSetType("tree");
    item.setAutoOpenTree("all");
    item.setValueField("id");
    item.setWrapTitle(false);
    item.setPickListWidth(350);
    item.setPickListFields(nameField, emailField);
    item.setPickListProperties(pickListProperties);

    item.setMultiple(true);
    item.setMultipleAppearance(MultipleAppearance.PICKLIST);

    ButtonItem btn = new ButtonItem("fetchData");
    btn.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    item.fetchData();
    }
    });

    ButtonItem addBtn = new ButtonItem("AddItem");
    addBtn.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    ListGridRecord rec = new ListGridRecord();
    rec.setAttribute("id", "Test" + counter);
    rec.setAttribute("name", "Test" + counter);
    rec.setAttribute("isFolder", false);
    ds.addData(rec);
    counter++;
    }
    });

    form.setItems(item, btn, addBtn);

    form.draw();

    }


    private static class TestDS extends DataSource {
    public TestDS() {
    setID("TestDS");
    setDataFormat(DSDataFormat.JSON);
    DataSourceField idField = new DataSourceField("id", FieldType.TEXT);
    idField.setPrimaryKey(true);
    DataSourceField parentidField = new DataSourceField("parentid", FieldType.TEXT);
    parentidField.setForeignKey("id");
    DataSourceField nameField = new DataSourceField("client", FieldType.TEXT);
    DataSourceField totalField = new DataSourceField("total", FieldType.FLOAT);
    DataSourceField crm_institutionField = new DataSourceField("crm_institution", FieldType.TEXT);
    setFields(idField, parentidField, nameField, totalField, crm_institutionField);

    setTitleField("client");

    setDataURL("./data.json");
    setClientOnly(true);
    }


    }

    }

    Json:


    [
    {
    "id": "Test0",
    "name": "Test0"
    },
    {
    "id": "HT",
    "name": "HT"
    },
    {
    "id": "HT|Paris",
    "name": "Paris",
    "parentid": "HT",
    "isFolder" : false
    },
    {
    "id": "HT|UK",
    "name": "UK",
    "parentid": "HT",
    "isFolder" : false
    },
    {
    "id": "HT|US",
    "name": "US",
    "parentid": "HT",
    "isFolder" : false
    },
    {
    "id": "HT|Madrid",
    "name": "Madrid",
    "parentid": "HT"
    },
    {
    "id": "Test",
    "name": "Test"
    },
    {
    "id": "Test2",
    "name": "Test2"
    }
    ]

    #2
    Both bugs have been fixed for builds dated December 14 and later.

    Comment


      #3
      Thank you for fixing these bugs.
      However, I found a new issue. Can it be fixed too, please?
      To recreate you can use the attached code.
      - Do full reload of TestTreeSelect2.html in browser (Ctrl+Reload in Chrome).
      - Enter value Test and click the SetValue button.
      - Open the drop down.
      Value Test will be set but sometimes it is not selected in the drop down.
      It is possible some race condition. To recreate you may need to reload the page several times.
      Click image for larger version

Name:	ItemIsNotSelected.png
Views:	213
Size:	15.4 KB
ID:	256195

      Code:
      package test2.client;
      
      import com.google.gwt.core.client.EntryPoint;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.data.DataSourceField;
      import com.smartgwt.client.types.DSDataFormat;
      import com.smartgwt.client.types.FieldType;
      import com.smartgwt.client.types.MultipleAppearance;
      import com.smartgwt.client.widgets.form.DynamicForm;
      import com.smartgwt.client.widgets.form.fields.ButtonItem;
      import com.smartgwt.client.widgets.form.fields.SelectItem;
      import com.smartgwt.client.widgets.form.fields.TextItem;
      import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
      import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.grid.ListGridField;
      import com.smartgwt.client.widgets.grid.ListGridRecord;
      
      /**
       * Entry point classes define <code>onModuleLoad()</code>.
       */
      public class TestTreeSelect2 implements EntryPoint {
      
          private int counter = 10;
      
          /**
           * This is the entry point method.
           */
          public void onModuleLoad() {
              DataSource ds = new TestDS();  
      
              final DynamicForm form = new DynamicForm();  
              form.setWidth(500);  
      
              ListGridField nameField = new ListGridField("name");  
              ListGridField emailField = new ListGridField("id");  
      
              ListGrid pickListProperties = new ListGrid();  
              pickListProperties.setAutoFitFieldWidths(true);  
      
              SelectItem item = new SelectItem("manager");  
              item.setTitle("Choose Manager");  
              item.setOptionDataSource(ds);  
              item.setDataSetType("tree");  
              item.setAutoOpenTree("all");  
              item.setValueField("id");
              item.setDisplayField("name");
              item.setSortField("name");
              item.setWrapTitle(false);  
              item.setPickListWidth(350);  
              item.setPickListFields(nameField, emailField);  
              item.setPickListProperties(pickListProperties);
      
              item.setMultiple(true);
              item.setMultipleAppearance(MultipleAppearance.PICKLIST);
      
              item.setAutoFetchData(false);
              item.setFetchMissingValues(false);
              item.setCachePickListResults(false);
      
              ButtonItem btn = new ButtonItem("fetchData");
              btn.addClickHandler(new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                      item.fetchData();
                  }
              });
      
              ButtonItem addBtn = new ButtonItem("AddItem");
              addBtn.addClickHandler(new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                      ListGridRecord rec = new ListGridRecord();
                      rec.setAttribute("id", "Test" + counter);
                      rec.setAttribute("name", "Test" + counter);
                      rec.setAttribute("isFolder", false);
                      ds.addData(rec);
                      counter++;
                  }
              });
      
              TextItem textItem = new TextItem("value");
              ButtonItem setValBtn = new ButtonItem("SetValue");
              setValBtn.addClickHandler(new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                      String value = textItem.getValueAsString();
                      if (value == null || value.isEmpty())
                          item.setValues(new String[0]);
                      else
                          item.setValues(new String[] {value});
                  }
              });
      
      
              form.setItems(item, btn, addBtn, textItem, setValBtn);  
      
              form.draw();         
      
          }
      
      
          private static class TestDS extends DataSource {
              public TestDS() {
                  setID("TestDS");
                  setDataFormat(DSDataFormat.JSON);
                  DataSourceField idField = new DataSourceField("id", FieldType.TEXT);
                  idField.setPrimaryKey(true);
                  DataSourceField parentidField = new DataSourceField("parentid", FieldType.TEXT);
                  parentidField.setForeignKey("id");
                  DataSourceField nameField = new DataSourceField("name", FieldType.TEXT);
                  DataSourceField isFolderField = new DataSourceField("isFolder", FieldType.BOOLEAN);
                  setFields(idField, parentidField, nameField, isFolderField);
      
                  setTitleField("name");
      
                  setDataURL("./data.json");
                  setClientOnly(true);
              }
      
      
          }
      
      }

      Json is the same as in previous post

      Comment


        #4
        What are these settings doing there?

        item.setFetchMissingValues(false);
        item.setCachePickListResults(false);
        These are abnormal and could create the problem. Try testing without them.

        Comment


          #5
          I removed setFetchMissingValues(false) and setCachePickListResults(false)
          Without them another sequence of events causes the same issue:

          - Do reload of TestTreeSelect2.html in browser
          - Enter value Test and click the SetValue button. Do not open the drop down.
          - Remove value Test from the text box and click the SetValue button (this will remove any selection).
          - Enter value Test and click the SetValue button.
          - Open the drop down.
          Value Test will be set but it is not selected in the drop down.

          Comment


            #6
            I did some debugging
            The reason of the issue: data.localData and data._allListCache are null before first opening of the select list.
            The record is not found because cache is null.
            This happens if select list is sorted.
            Click image for larger version

Name:	ItemIsNotSelectedDeb.png
Views:	109
Size:	18.3 KB
ID:	256209

            Comment


              #7
              Yes, we're looking into the fix as we speak - we'll update here shortly

              Comment


                #8
                We've made a change to address the missing cache - you can test the fix in builds dated December 19 and later.

                Note that if you're trying to clear the value with item.setValues(new String[0]), you should use item.clearValue() instead, since an empty array is not the same as no value.
                Last edited by Isomorphic; 18 Dec 2018, 07:27.

                Comment

                Working...
                X