Search code examples
importhierarchyform-datasetvalueeclipse-scout

Eclipse Scout Neon on value set validation detect loop


I want to validate fields dependencies with other field when current field has changed.

Basic idea is that if I have field A and fields B,C,D,E,... and there is some complex dependencies graph on those fields, I would like to have it solve like this :

  • When I set value A export form data (current state of form)
  • form data is send to scout server
  • on scout server dependencies graph is calculated and resolved (we get list in order)
  • call setters of fields in ordered list which "fix" form data
  • Import form data at the end.

My problem is that if I trigger this event in

 @Override
protected void execChangedValue() {
    // trigger export
    // trigger server validation
    // trigger import
}

I get

2016-06-03 13:31:28,468 WARN  scout-model-thread-22 o.e.s.rt.client.ui.form.fields.AbstractValueField - Loop detection in ...$FieldA with value 101191 [m4042 @   ]
java.lang.Exception: null

How to fix this?

I even have a problem that, if I get error back, I want to abort import and set old value back.

 @Override
protected void execChangedValue() {
    // trigger export
    // trigger server validation
    if (error) {
        setValueWithoutTrigger(oldValue)
    } else {
        // trigger import
    }
}

What is oldValue it doesn't matter, it could be null. (so reset value when error). Method setValueWithoutTrigger is same as setValue() but before set value it called this.setValueChangeTriggerEnabled(false);

I know it somehow could be done, because I saw similar functionality in BSI code.


Solution

  • It is not possible to set the value of a field in the execChangedValue method of the same field. The framework detects a loop here.

    What you could do instead is to use the method execValidateValue as follows

    @Override
    protected String execValidateValue(String rawValue) throws ProcessingException {
        MyFormData formData = new MyFormData();
        exportFormData(formData);
        formData = sendFormDataToServerAndDoValidation();
        importBCDE(formData);
        return formData.getTest().getValue();
      }
    

    The method importBCDE would set fields B, C, D, and E, but not field A.