PropertysetItem with ComboBox ???

Hi to all,
for my application I need to use PropertysetItem instead of BeanItem: the reason it that the forms are built dynamically according a data base, that describes field names, types, regex for validation and so…

The book of Vaadin does not contains many examples about it, it says [quote]
use the ready BeanItem adapter to bind the form to any JavaBean object. You can also use PropertysetItem to bind the form to an ad hoc set of Property objects, resembling a Map.
[/quote] …and then it start to explain the use of JavaBean :frowning:
There is a small example, but only with Textfields.

I wrote this code, that it works very well for textfield (for sure, it is exactly like in book of Vaadin) but it does not work for ComboBox, Select, etc…
The problem is the line in red; if I comment it, the ComboBox is correctly drawn, with its options…but it is not added to form data source so I cannot retrieve the values set by the user.
If I uncomment it, instead of a Combobox, a TextBox is drawn, with a default text inside it equals to ObjectProperty constructor parameter (in this case “”).

So PropertysetItem must be used in a different way in Combobox to make it works, unfortunately I have not found examples…Someone can help me ?

Thanks very much!

public abstract class DictionaryForm extends Form {
  protected final PropertysetItem formData = new PropertysetItem();

    public DictionaryForm(List<ItemDictionaryObj> itemDictionaryObj, Layout formLayout) {

private void init(List<ItemDictionaryObj> itemDictionaryObj) {
        for (ItemDictionaryObj obj : itemDictionaryObj) {
            ItemDictionaryObj.Type type = obj.getType();
            String ID = obj.getID();
            boolean obbligatory = obj.isObbligatory();
            if (type.equals(ItemDictionaryObj.Type.TEXTFIELD)) {
                TextField textField = new TextField(obj.getLabel());

                this.addField(ID, textField);
                formData.addItemProperty(ID, new ObjectProperty<String>(""));
            } else if (type.equals(ItemDictionaryObj.Type.SELECT)) {
                ComboBox select = new ComboBox(obj.getLabel());

                for (SelectBoxObj boxObj : obj.getList()) {
                    String itemID = boxObj.getValue();
                    select.setItemCaption(itemID, boxObj.getLabel());
                this.addField(ID, select);              
formData.addItemProperty(ID, new ObjectProperty<String>("")); 
            } else if (type.equals(ItemDictionaryObj.Type.CUSTOM)) {


I found a workaround to this problem using a custom FormFieldFactory instead of calling directly addField(ID, select) from the form but I am still curious to know if there is a different solution…

hi enrico,

did you come across a solution to this? i am considering vaadin for the exact purpose you have listed above (create dynamic forms from field criteria saved in db), but i am really struggling to find the right solution.



anyone have any ideas?

I’m also looking for the correct way to use a ComboBox with a FieldGroup, so that validation on my ComboBox will be functional.

Currently I am doing this:

private ComboBox msgTypeSel;

PropertysetItem item = new PropertysetItem();

// Code to initialize combo box

// Below line when uncommented breaks validation so that the form submission is immediately called
// item.addItemProperty(“messageType”, msgTypeSel);

// This line works as far as resulting in a working validator, but a null selection option is added
item.addItemProperty(“messageType”, new ObjectProperty(“Select Message Type Default”, String.class));

I’m guessing what I’m doing wrong include the following:

  1. Using PropertysetItem instead of a more appropriate class
  2. Using ObjectProperty for the ComboBox instead of a more appropriate implementation of Property

So, my ComboBox is almost properly populated with options, except there is an unwanted null selection option at the top, and validation works as expected.

Hi there,

i found an workaround in this thread:!/thread/3183746

the workaround is to bind the Field direct with

ComboBox combobox = new ComboBox(keys.getName());
combobox.addItems("Io", "Europa", "Ganymedes", "Callisto");
fieldGroup.bind(combobox,keys.getName() );

sorry i forgot something:

item = new PropertysetItem();
fieldGroup = new FieldGroup(item);

ComboBox combobox = new ComboBox("combi");
combobox.addItems("Io", "Europa", "Ganymedes", "Callisto");
/* Adds the field to my extendet FormLayout */

/* We must set a Property 'combi' for the combobox */
item.addItemProperty("combi", new ObjectProperty<String>(""));

/* this binds the combobox to the name 'combi' */
fieldGroup.bind(combobox,"combi" );

You can get the container of all the Items that you have. Then as they are RowItems (if not you can use BeanItems) you have to create a custom Converter (RowIdToInteger) and than you can rappresent into combox the values of a specific property of the item

ComboBox combobox = new ComboBox();
combobox.setItemCaptionPropertyId(“TITLE”); // the item’s property that you want to view into combobox
combobox.setConverter(new RowIdToIntegerConverter());