Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
NativeSelect won't let me unselect a value once set
I have a NativeSelect that won't let me unset a value once it has a value. I allow null selections and required is false, but while it can be null initially, once a value is chosen, I cannot unselect (have it go back to being a null value). I tried a value change listener, and only when I select one of the values in the list does it work, but if I try to choose the "blank line" to have no value set again, no value change event occurs.
Basic code to create it looks like this under Vaadin 7.6.5:
if ( propertyId.equals("overridePackageDocumentId") ) {
NativeSelect select = new NativeSelect(vaadinUi.getMsg("PackagePartyToDocumentPartyForm.overridePackageDocumentId.label"));
select.setDescription(vaadinUi.getMsg("PackagePartyToDocumentPartyForm.overridePackageDocumentId.tooltip"));
select.setNullSelectionAllowed(true);
select.setImmediate(true);
select.setRequired(false);
select.setMultiSelect(false);
select.addValidator(new SelectValidator(select));
select.setItemCaptionMode(ItemCaptionMode.EXPLICIT);
Collection<Library> libraries = Library.Manager.getForUserWithViewDetailsPermission(vaadinUi.getUser(), Library.INCLUDE.ONLY_ENABLED);
for( Library library : libraries ) {
Collection<DocumentInfo> documents = DocumentInfo.Manager.getAll(library,DocumentInfo.INCLUDE.ONLY_ENABLED);
for( DocumentInfo docInfo : documents ) {
select.addItem(docInfo.getId());
select.setItemCaption(docInfo.getId(), library.getPathName().toString() + "/" + docInfo.getEsfName().toString());
}
}
return select;
}
Answered my own question!
I was missing the select.setNullSelectionItemId(nullId) that specifies the ID to return when nothing is selected.