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:
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
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);
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
Comment