Two Way Binding of Vaadin Components and Model Objects

Changing the Vaadin Component property value also changes the corresponding Model property value.
Changing the Model property value also changes the corresponding Vaadin Component property value.

Code explanation.


public final class PersonUiModel {
    public static final String PROP_FIRST_NAME = "First Name";
    public static final String PROP_SELECTED_ADRESS = "Address";
    public static final String PROP_ADDRESSES = "Addresses";

    private String firstName;
    private String selectedAddress = null;
    prvate List<String> address = new ArrayList<String>();
   
    public Person(final String firstName, List<String> address) {
        this.firstName = firstName;
        this.address = addresses;
    }

   // getters/setters
}


public class PersonTest {
    @Test
    public void firstNameBound() {
        final PersonUiModel person = new PersonUiModel("George");
        final TextField firstNameField = VaadinComponentFactory.createTextField(person, Person.PROP_FIRST_NAME);
 
        assertEquals("George", firstNameField.getValue());
        
        firstNameField.setValue("Nancy"); 
        assertEquals(person.getValue("Nancy");

        person.setFirstName("Willy");
        assertEquals("Willy", firstNameField.getValue());
    }

    @Test
    public void addressBound()
    {
        final PersonUiModel person = new PersonUiModel("George", Arrays.asList("123 Street", "456 Lane");
        final NativeSelect addressSelect = VaadinComponentFactory.createNativeSelect(person, Person.PROP_SELECTED_ADDRESS, Person.PROP_ADDRESSES);
       
        // same asserts for firstName test
        // ...

       assertEquals(null, addressSelect.value());

       assertEquals(2, addressSelect.size());       
       Iterator iter = addressSelect.getItemIds().iterator();
       assertEquals("123 Street", iter.next());
       assertEquals("456 Lane", iter.next());
       
       // more asserts for changing value of selected address in both component and model
     
       // more asserts for changing values in address list in model
    }
    
}

I have implemented the above code except for updating the Native Select list of values when the model list values change. Also, this doesn’t handle binding to boolean values like visible, only to the value property and list values.

Is something like this a wanted feature in Vaadin, either as part of the core or as an Add On?
Or is the Beans Binding JSR a better way to go?
Any thoughts are appreciated.

I’d say this is worth at least an add-on.

Getting it into the core might be harder, but by making it available for others easily via the Directory, where everyone can rate it might help get it accepted.