Announcement

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

    FormItem display value cache problem

    Hi,

    I've got a ListGrid with connected DynamicForm.

    On record I've got client_id that refers to another DataSource.

    I'm trying to make StaticTextItem with option data source that will display name of a client with his image.
    I've implemented FormItemValueFormatter() and it works fine until displayValue cache kicks in.

    As I've studied FormItem caches display field values from optionDataSource and it's great but why it ignores FormItemValueFormatter??

    Should those values be cached??

    Is there any way to force that formatted values be cached or maybe manually update this cache??
    Or maybe there is other way to accomplish this?

    #2
    Make sure you're testing against the latest patched build, then if the problem persists, please describe a way it can be reproduced, and remember to always post which product and version you are using,

    Comment


      #3
      I'm using SmartGWT v12.0p_2018-09-03 (2018-09-03)
      Problem appears from quite some time, so it's not new.

      Stand alone test case using datasource from showcase:

      Code:
              VLayout layout = new VLayout();
              layout.setWidth100();
      
              DynamicForm form = new DynamicForm();
              form.setDataSource(ItemSupplyXmlDS.getInstance());
              form.setUseAllDataSourceFields(true);
      
              StaticTextItem item = new StaticTextItem("category");
              item.setOptionDataSource(SupplyCategoryXmlDS.getInstance());
              item.setValueField("categoryName");
              item.setDisplayField("categoryName");
      
      
              item.setValueFormatter(new FormItemValueFormatter() {
      
                  @Override
                  public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
                      if(value == null) {
                          return "NULL";
                      }
      
                      Record optionRecord = item.getSelectedRecord();
                      if(optionRecord == null) {
                          return "No Record: " + value;
                      }
      
      
                      return optionRecord.getAttribute("parentID") + " - " + value;
                  }
              });
              form.setFields(item);
      
              ListGrid listGrid = new ListGrid();
              listGrid.setWidth100();
              listGrid.setHeight(300);
              listGrid.setDataSource(ItemSupplyXmlDS.getInstance());
              listGrid.setAutoFetchData(true);
      
              listGrid.setUseAllDataSourceFields(true);
      
              listGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
      
                  @Override
                  public void onSelectionChanged(SelectionEvent event) {
                      form.editSelectedData(listGrid);
                  }
              });
      
              layout.addMember(listGrid);
              layout.addMember(form);
      
              this.addChild(layout);

      It's not real use case but describes problem.
      Select various records with different category.

      First it will show parentId with category name. But when we change to record with different category and than switch back we got No Record message.


      Comment


        #4
        The problem here is that you are assuming the record is always immediately available. In fact the item only guarantees that it will retrieve the displayValue, and doesn't make guarantees about the full record being available. You need to fetch the record yourself if you want the whole thing.

        Note this does differ for SelectItem and ComboBoxItem, where a set of records is actually loaded for the picklist, so it's easy to just make the selected record available.

        Comment


          #5
          There is some difference between SelectItem but it doesn't solve my problem. And I see even stranger behaviour.
          Lets switch datasources because category DS is quite small and all fits in cache.

          Code:
                  VLayout layout = new VLayout();
                  layout.setWidth100();
          
                  DynamicForm form = new DynamicForm();
                  form.setDataSource(SupplyCategoryXmlDS.getInstance());
                  form.setUseAllDataSourceFields(true);
          
          //        StaticTextItem item = new StaticTextItem("categoryName");
          
                  SelectItem item = new SelectItem("categoryName");
                  item.setOptionDataSource(ItemSupplyXmlDS.getInstance());
                  item.setValueField("category");
                  item.setDisplayField("itemName");
          
                  item.setValueFormatter(new FormItemValueFormatter() {
          
                      @Override
                      public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
                          if(value == null) {
                              return "NULL";
                          }
          
                          Record optionRecord = item.getSelectedRecord();
                          if(optionRecord == null) {
                              return "No Record: " + value;
                          }
          
          
                          return optionRecord.getAttribute("itemID") + " - " + value;
                      }
                  });
                  form.setFields(item);
          
                  ListGrid listGrid = new ListGrid();
                  listGrid.setWidth100();
                  listGrid.setHeight(300);
                  listGrid.setDataSource(SupplyCategoryXmlDS.getInstance());
                  listGrid.setAutoFetchData(true);
          
                  listGrid.setUseAllDataSourceFields(true);
          
                  listGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
          
                      @Override
                      public void onSelectionChanged(SelectionEvent event) {
                          form.editSelectedData(listGrid);
                      }
                  });
          
                  layout.addMember(listGrid);
                  layout.addMember(form);
          
                  this.addChild(layout);
          Now do the same.
          On small data source it works fine.
          It's better visible with server side communication. Select Item fetches 75 records and stick to it.
          After that same displayValue cache kicks in and we are back.

          Main difference between StaticTextItem and SelectItem in this case is with StaticTextItem cache is building in per record basis but in SelectItem it first fetches 75 records and if we select only records in this range it works fine. When we exceed behaviour comes back to the same with StaticTextItem.

          The simplest way to solve this would be if the displayValue cache was building with return value of FormItemValueFormatter.
          It there a way to overwrite some methods and apply this behaviour?




          Comment


            #6
            We've made a change which should address this issue. Please try the next nightly build, dated September 18 or above

            Regards
            Isomorphic Software

            Comment


              #7
              Tested and works like a charm.
              Thank you very much.

              Best regards
              Mariusz Goch

              Comment

              Working...
              X