Announcement

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

    setReadOnlyWhen creates race with editRecord()

    Hi,

    I've found a problem that appears when setReadOnlyWhen() condition us used.
    I've spent couple hours to isolate this problem to minimal test case.
    See this example:
    Code:
            DataSource ds = new DataSource();
            ds.setClientOnly(true);
    
            DataSourceIntegerField fieldId = new DataSourceIntegerField("id");
            fieldId.setPrimaryKey(true);
            ds.addField(fieldId);
            ds.addField(new DataSourceTextField("field1"));
            ds.addField(new DataSourceTextField("field2"));
    
            DataSourceTextField fieldStatus = new DataSourceTextField("status");
    
            LinkedHashMap<String,String> map = new LinkedHashMap<String,String>();
            map.put("new", "NEW");
            map.put("progress", "Progress");
            map.put("finished", "Finished");
            map.put("canceled", "Canceled");
            fieldStatus.setValueMap(map);
            ds.addField(fieldStatus);
    
            VLayout layout1 = new VLayout(5);
            layout1.setGroupTitle("vm1");
    
            ValuesManager vm1 = new ValuesManager();
            vm1.setDataSource(ds);
    
            DynamicForm form1 = new DynamicForm();
            form1.setDataSource(ds);
            form1.setValuesManager(vm1);
    
            TextItem itemField1 = new TextItem("field1");
            itemField1.setReadOnlyWhen(new AdvancedCriteria("status", OperatorId.IN_SET, new String[] {"finished", "canceled"}));
            itemField1.setReadOnlyDisplay(ReadOnlyDisplayAppearance.STATIC);
    
            SelectItem itemField2 = new SelectItem("field2");
            itemField2.setDefaultValue("default");
            itemField2.setValueMap("new", "default", "aaa");
    
            SelectItem itemStatus = new SelectItem("status");
            itemStatus.setDefaultValue("new");
    
            form1.setFields(
                    new TextItem("id"),
                    itemField1,
                    itemField2,
                    itemStatus
            );
            layout1.addMember(form1);
    
            Button button = new Button();
            button.addClickHandler(new ClickHandler() {
    
                @Override
                public void onClick(ClickEvent event) {
                    vm1.clearValues();
    
                    Record r = new Record();
                    r.setAttribute("id", 1);
                    r.setAttribute("field1", 123);
                    r.setAttribute("status", "finished");
    
                    vm1.editRecord(r);
                }
            });
            layout1.addMember(button);
    
            Record r = new Record();
            r.setAttribute("id", 1);
    
            vm1.editRecord(r);
    
            this.addChild(layout1);
    When you click a button look at status field. It changes properly to finished. But when you change it manually to other value ex Progress and then click a button value changes to NEW.

    I've found that it's connected to three things:
    - setReadOnlyWhen()
    - vm.clearValues()
    - vm.editRecord()

    When I remove clearValues() or setReadOnlyWhen() everything works fine. But with this combination I've figured there is a race started with clearValues() and editRecord() and we end up with default value for SelectItem. Don't know why but if affects only SelectItem.
    Strange thing is that race occurs only when a user manually change value of SelectItem. If he doesn't, field value changes as expected.

    In my application I commonly used combination of clearValues() and editRecord() right after. And when I added setReadOnlyWhen() conditions these strange behavior appeared.
    It could lead to misleading an end user so probably it's worth fixing.
    Tested on latest nightly

    Additional question can I just get rid of clearValues() before editRecord() ??

    Best regards
    Mariusz Goch

    #2
    Looking at this. Assuming we can reproduce it, that's a bad bug and we appreciate the effort to reproduce it!

    As far as your question, yes, clearValues() should be unnecessary here, because editRecord() means that the entire form is going to take on the values of the Record passed to editRecord(). So it should not be necessary to clear anything before your editRecord() call.

    Comment


      #3
      We've made a change to address this issue. Please try the next nightly build dated May 11 or above, in the 13.0 or 13.1 branches

      Regards
      Isomorphic Software

      Comment


        #4
        Hi,

        I've removed clearValues() before as you suggested but to test this case I've reverted to version with this problem and I confirm that in latest version it's fixed.
        I don't see any race and SelectItem values are correct.

        Best regards
        Mariusz Goch

        Comment


          #5
          Great, thank you for confirming!

          Comment

          Working...
          X