vaadin / form-filler-addon

Other
4 stars 0 forks source link

Integration with Flow Binder #113

Open mshabarov opened 1 year ago

mshabarov commented 1 year ago

Usually when the form auto-filling is done, the resulted data from the input fields is being validated and persisted to a database. Form Filler add-on could make this process more automatic with less boilerplate code, having the Binder as an input and giving a bean as output. The user case is the following:

  1. Input a raw content as a text or image
  2. Click a button, start the form filling
  3. Check for input fields validation errors
  4. Check for recommendations from application about fields where form filler couldn't populate data
  5. Do manual corrections or type in the values manually where needed
  6. Click on "Save" button
  7. Redo 3-6 step until validation passes.

Step 3 can be done automatically by Form Filler and for step 4 you could have an API in Form Filler that gives you a list of recommendations mapped to the input fields ID/names/labels, so that these recommendations can be placed to the UI.

Suppose you have an entity class:

public class Entity implements Serializable {
       String name;
       String address;
}

and Binder object:

Binder<Entity> binder = new Binder<>(Entity.class);
binder.bind(nameField, Entity::getName, Entity::setName);
binder.bind(addressField, Entity::getAddress, Entity::setAddress);
binder.withValidator(entity -> /* any validation logic*/,
                        "Name must contain ...");

you should be able to set it to Form Filler:

FormFiller formFiller = new FormFiller(formLayout);
formFiller.setBinder(binder);
FormFillerResult result = formFiller.fill(inputText);

If the binder is specified, form filler should make a validation and prepare a bean if it's valid or give recommendations:

Entity myEntity = result.getBean();
Collection<FormFillerRecommendation> recommendations = 
              result.getRecommendations();

Bean validation errors can be handled with Binder directly. For the further validations (points 6-7) the Binder should be used directly.