Search code examples
formsform-dataeclipse-scout

Eclipse Scout go through fields in form data


I would like to go through all fields in form data.

I know that in form I could do something like this :

 // Go through all fields with IFormFieldVisitor
box.visitFields(new IFormFieldVisitor() {

  @Override
  public boolean visitField(IFormField field, int level, int fieldIndex) {

    if (field instanceof MyClass) {
      ...
    }
    return true;
  }
}, 0);

but form data doesn't have this options. How to do this in form data.


Solution

  • You can obtain them using

    1. AbstractFormData.getFields to obtain the top-level fields. If you need nested fields as well, have a look at the more complex AbstractFormData.getAllFieldsRec().
    2. AbstractFormData.getAllProperties to obtain properties that you have defined by annotating the getters and setters with @FormData

    That was the simple case.

    Now, if you are using the Scout Extension mechanism to add new elements to an existing form (and it's formdata), you will have to take those contributions into account. If you need to do this, you can refer to the source code of the AbstractForm.importFormData to see how Scout implements this.