1

I'm trying to create form with Vaadin using "Binding form to data" with this class:

public class Job {

    private String nom_projet;
    private String svn;
    private String planning1;
    private String planning2;
    private String goals;
}

with getters and setters.

When I try this everything works fine:

final Form form = new Form();
Job bean = new Job();
BeanItem<Job> item = new BeanItem<Job>(bean);
form.setItemDataSource(item);

I tried to add a custom field like its described in "Book of Vaadin" so I created this class:

public class MyFieldFactory implements FormFieldFactory  {

    private static final long serialVersionUID = 1L;

    public Field createField(Item item, Object propertyId, Component uiContext) {
        Select select = new Select("goals");
        select.addItem("compiler:compile");
        select.addItem("clean install");
        select.addItem("clean");
        select.addItem("package");
        select.addItem("test");
        select.setNewItemsAllowed(true);
        return select;
    }
}

But when I wanted to add this statement to MyApplication.java:

form.setFieldFactory(new MyFieldFactory());

I got "setFieldFactory" underlined and 3 choices:

  • () Cast argument 1 to FieldFactory
  • Change to setFirldFormFactory(...)
  • Let 'MyFieldFactory' implements 'FieldFactory'

When I click on:

  • Let 'MyFieldFactory' implements 'FieldFactory'

custom field does not appear in form.

4

1 回答 1

2

setFieldFactory方法采用一个FieldFactory作为参数,您的MyFieldFactory类实现FormFieldFactory不一样。

在 Vaadin javadoc 中,setFieldFactoryis 标记为已弃用,它们提示您改为使用setFormFieldFactory(FormFieldFactory formFieldFactory)

使用此方法将解决您的问题。

问候。

于 2012-04-17T00:55:57.943 回答