Vaadin 8 ComboBox and empty selection

when trying to use a ComboBox, I tried to set the empty selection caption with the followings

setEmptySelectionCaption(“My empty caption”);

The empty caption appears well in the Combobox menu, but once selected, the selected value is always blank, whatever I did. And setting it programmtically with setValue (null) does not make it appear

I check the setItemCaptionGenerator, but my lambda expression is not called with a null value.

Did I completly miss something, or is there a bug ? I’m using 8.0.5

Thanks in advance

Hi Eric,

I also have tried to set EmptySelection as you did and some other ways, but result was the same- the caption is not shown in the selectedField.
I have found a “workaround”, but in this case you have to set null, but you can manapulate with it on server side the way you want.

List planets = new ArrayList<>();

    ComboBox<String> select = new ComboBox<>("Select or Add a Planet");
    select.setItemCaptionGenerator( c-> c==null? "EMPTY VALUE" : String.valueOf(c));
    Button a = new Button("choose");
    a.addClickListener(event -> {
   //This prints item itself;it could be Optional.empty, if it was null or Optional[Mercury]

    select.addSelectionListener(event -> {

        //This prints caption. "EMPTY VALUE" or Mercury

[/code]You will get the result you want, but I suggest you to create a bugticket to if you will so.

Hopefully it helps,
Best regards,

Thanks for trying. I did enter a bug

Best regards


Is this bug already fixed in Vaadin 8.1.6? I’m asking as I struggle with a similar behaviour. I’m using the NativeSelect component and in fact I can select the emptySelectionCaption and it also gets displayed. My problem is, that the object does not display the emptySelectionCaption when it is initialized with an emptyValue, neither if the null value comes from the databinding nor if I set it manually by nativeSelect.setValue(null)

Any ideas why the emptySelectionCaption is not display initially?

I’m guessing that that’s another instance of the same bug. It was fixed for ComboBox, but still remains in NativeSelect. Can you create a ticket with a small code sample at
? You can reference there.