0
votes

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.

1
I don't get the point. As far as I understand, you want to calculate the values of fields B, C, D, and E on the server. Why would you then need to define execChangedValue() methods on the client?Samuel Renold
I don't understand your comment. What then would trigger check on server side if not execChangedValue()? If I want trigger validation on server when user change some data in field A, it need to be triggered from client, and execChangedValue seems to me like a right spot.Marko Zadravec
You are right. Now I understand your question. Thank you.Samuel Renold

1 Answers

0
votes

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.