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;
}