How to set the value to show in a ComboBox?
Basically I have a key-value POJO, which have two fields, a key, and a value, then I create a bunch of items into a collection:
List<KeyValuePojo> pojos = Arrays.asList(
new KeyValuePojo( "key1", "value1" ),
new KeyValuePojo( "key2", "value2" ),
new KeyValuePojo( "key3", "value3" ),
new KeyValuePojo( "key4", "value4" )
);
Then I create a ComboBox, and set the pojos collection as DataSource, and forbid null selection because I want the user to choose one from the list.
ComboBox myCombo = new ComboBox("caption", pojos);
myCombo.setNullSelectionAllowed(false);
Then I want to choose one by default, lets say the first one.
Collection<?> itemIds = myCombo.getItemIds();
Object defaultValue = myCombo.getItem(itemIds.iterator().next());
myCombo.setValue(defaultValue);
If I ask for the value of myCombo, it returns me the pojo with key=“key1” and value=“value1”, but at the screen I only see a comboBox with nothing selected.
I’ve tried repainting the content, calling the setValue after and before addding it to any layout and i’ve tried too using the method select(Object itemId) instead, but the problem is still there.
does anybody know what’s happening?