Designer Components Data Binding using Annotation


I am trying to bind the various components in my Vaadin Designer page using PropertysetItem and FieldGroup binding.

Where do i need to put @PropertyId(“name”) binding for say my textfield in Designer Form?
I am designing forms using Vaadin Designer
The .Java file is non-editable and overwritten for Design Form.

Hi Abhishek,

As far as I know this is not (yet at least) possble because, as you noted, the Java file gets owerwritten when you change the design.

However, there are a couple of ways to work around this:

  1. Name your fields in the designer so that they map 1:1 against the properties in your fieldGroup, then the fieldGroup will be able to find it. However, this will not work for nested properties.
  2. Extend the generated Java class and add a method that will manually bind a specific field to a specific property

For instance like this:

public class MyBean {
        private String autoBinding = "";
        private String myCustomProperty = "";

       //Getters and setters omitted

@DesignRoot public class MyDesign extends VerticalLayout { public TextField autoBinding; public TextField nonAutoBinding; public MyDesign() {; } } [code]
public class MyForm extends MyDesign {

     public void bind(FieldGroup binder) {
        // Bind all the fields that map by name

        //Manually bind the remaining fields, for instance neted properties. 
        binder.bind(nonAutoBinding, "myCustomProperty");

[/code]Then in your UI code:

        MyForm myForm = new MyForm();
        final BeanFieldGroup<MyBean> beanFieldGroup = new BeanFieldGroup<MyBean>(MyBean.class);
        beanFieldGroup.setItemDataSource(new MyBean());

Hope this helps


Edit: added MyBean for reference.

Thanks Petri.

This will solve my problem .
Only thing is i was trying to search for such annotation option for binding so as to ease it.

Looking forward for this as an enhancement in future version of Vaadin .