Combobox nullselection dissapears

I’ve got a collection of items (let’s say they’re objects of class A) from database placed into a combobox with a beancontainer, and I’ve set the value of setNullSelectionAllowed() to true. If I don’t do anything else then upon running the application when I click on the dropdown I can see an empty slot.

However if I try to set a nullselection object like this

A item = new A(); item.name("Add new item"); comboBox_location.setNullSelectionItemId(item); comboBox_location.select(comboBox_location.getNullSelectionItemId()); The item disappears completely. No item is selected and in the dropdown menu I can’t see the null item, only the items from the bean container.

You need to add the null item to your container too, try something like this:

A item = new A();
comboBox_location.addItem(item);
comboBox_location.setItemCaption(item, "Add new item");
comboBox_location.setNullSelectionItemId(item);
comboBox_location.select(item);

Thanks for the reply. This now successfully adds the item to the combobox but the select doesn’t seem to work. What I mean is when the view opens nothing is selected even though the select method is called on the null selection, and the null selection item is in the container. If I select something else, and then the null item it suddenly works.

Hi,

sorry, this was my mistake. You should obviously select null and not the item, since the item is now the nullSelectionItemId. So changing line 5 to

comboBox_location.select(null);

should do the trick.

-tepi

Thanks for the quick reply. I’ve already tried that and it did not work.

a) No item is displayed as selected
b) ValueChange event is not triggered

Hi,

can you post the complete code you’re using? The following simple case works for me and the item with ID 4 is selected when the component is rendered:

ComboBox cb = new ComboBox();
cb.addItem(1);
cb.addItem(2);
cb.addItem(3);
cb.addItem(4);
cb.setItemCaption(4, "null item");
cb.setNullSelectionItemId(4);
cb.select(4);