ComboBox : Empty items

Hello,

When I try to add some items in a combo box, they are added but the text of the elements is not displayed.
The combo box is created in my designer and I add items like that :

cb_stage_technologie.addItem("test");

Thomas Binsfeld
IT Student

Works fine with me. What Vaadin version are you using? Are you sure
cb_stage_technologie
is the combobox displayed in your ui?

I use Vaadin 7, Designer in alpha version and Valo theme.

I’m sure that cb_stage_technologie is the component I placed with the designer.

Can you attach your codes here?

In public class Dashboard extends Dashboard_design implements View, I have this in the constructor :

// Combo box // Doesn't work : (detect elements but doesn't display them) cb_stage_technologie.addItem("Stage"); // TODO : DELETE THIS cb_stage_technologie.addItem("TFE"); In public class Dashboard_design extends CssLayout, the designer wrote this :

protected com.vaadin.ui.ComboBox cb_stage_technologie;

And it looks like this in the browsers :

You see, it detects my elements but the text is not displayed.

It feels like something is calling combobox.setItemCaptionPropertyId(property) or combobox.setItemCaptionMode(ItemCaptionMode) somewhere.

I don’t know if you are familiar with Vaadin’s data structure or not, but ComboBox uses always a Container to store the data. A container contains a set of items, and every item contains a set of properties. The same structure that goes into Table and other components as well. When you call combobox.addItem(“something”); it is actually a shorthand for combobox.getContainerDataSource.addItem(“something”);

As ComboBox shows a string to represent a row, it can only use one possible value from the whole item. Specifying which value it should use is done with combobox.setItemCaptionPropertyId(property). You can set it to show any property, but the default is that it takes itemId.toString(). When you do combobox.addItem(Object), that Object becomes the itemId. As you are using strings as itemId, they should be outputted directly to the UI.

So again, it feels like something is overriding the default behaviour. Not sure if it is your own code of if Designer does that, and hard to say without seeing the full html and java files. I haven’t used Designer in a while so I’m not sure what it does there today. I could fire up Eclipse and test this example.

Okay I tested it and I got the exact same problem. I checked the source of the declarative file that the deigner creates and I found this:

<v-combo-box item-caption-mode="item" _id="myCombo"></v-combo-box> So it actually changes the caption mode per default. By deleting the item-caption-mode=“item” resolves the issue.

It works, thank you !