Search code examples
form-dataeclipse-scout

Eclipse scout neon import form data in abstract box on field change


I have abstract group box. Inside this group box I have smart field, and on change I would like to fill some other fields in form.

Problems are :

  • on abstract group box new box form data can't be created.
  • if I try to import form data, because import form data called setValue loop is detected.

My try was to change abstract group box to "normal group box" and set values like this :

@Override
protected void execChangedValue() {
    AbstractCarSelectionBoxData formData = new AbstractCarSelectionBoxData();
    FormDataUtility.exportFormData(this.getParentField(), formData);
    formData = BEANS.get(IOfferFormService.class).loadCarInformations(formData);
    FormDataUtility.importFormFieldData(this.getParentField(), formData, false, null, null);
}

This approach actually work, and fill the data, but I get

2016-03-22 10:18:57,448 WARN  scout-model-thread-20 o.e.s.rt.client.ui.form.fields.AbstractValueField - Loop detection in com.sixt.leasing.scout.client.template.AbstractCarBox$CarTypeSixtField with value 279096 [m4042 @   ]
java.lang.Exception: null
         at org.eclipse.scout.rt.client.ui.form.fields.AbstractValueField.setValue(AbstractValueField.java:324) [org.eclipse.scout.rt.client-5.2.0.M5.jar:5.2.0.M5]
         at org.eclipse.scout.rt.client.ui.form.fields.AbstractValueField.importFormFieldData(AbstractValueField.java:219) [org.eclipse.scout.rt.client-5.2.0.M5.jar:5.2.0.M5]

What is right approach to deal with this case?

I know that I could always get only the DTO object and set values in client, but this is not what I would like to have...


Solution

  • Solution for problem 1

    Create an abstract method AbstractCarSelectionBoxData createNewBoxData(); in AbstractCarSelectionBox and implement it in the corresponding subclasses returning the new form data, e.g. new MyFormDataContainingCarSelectionBox().getCarSelectionBox();.

    Solution for problem 2

    Before importing the form data, call setValueSet(false) on the field that triggered the execChangedValue, e.g. formData.getMySmartfield().setValueSet(false). This will make sure that it's not imported into the form, thus no loop detection should occur.