Binding a form to a bean array


I’m trying to bind a bean to a form,
The bean has a String array, i want to generate a editable textfield for each item in the array and use the vaadin binding.

public class ExampleBean {

    private String name;
    private String displayName;
    private String[] parameters;

I have tried this using a class extending CustomField<String> but have failed.

Is there a simple way to support the array inside a bean and use the vaadin binding methods?

Are there any thoughts/ideas? I’m running into a similar situation.

Many thanks

One of the issues is that there is no obvious answer to what this would mean and how the user might want to edit the contents of the array. Should it be possible to select Strings from some set/list into the array? Edit a fixed number of strings? Add or remove Strings? Edit a set of references to other objects? Edit each of the beans in the array with a separate nested form? Something else?

That said, a CustomField is probably what you want. I have used CustomField with Collections of different kinds but not with arrays, but the idea is the same.

An alternative to that would be creating a custom Property class and using it in your items. However, with this approach, if the items are in a Container e.g. to be displayed in a Table, the number of items in the array should be constant.

What!? Vaadin isn’t able to read the mind of the developer!? How disappointing :wink:

I solved the issue by iterating over the list and creating the required fields dynamically. I added a changeValueListener for each item which sets the value of the associated field.
Works perfectly :slight_smile: