For some reason, if I enter a non-existent value into my combo, it creates the entity multiple times. I press enter, it gets added, I click the arrow, it gets added again. The code is getting called from Select.changeVariables. Not quite sure if this is some sort of a bug, or if I’m doing something wrong…
triggerSelector = new ComboBox("", getService().getTriggerContainer()) {
{
setItemCaptionPropertyId("name");
setNewItemsAllowed(true);
setImmediate(true);
setNewItemHandler(
new NewItemHandler() {
@Override
public void addNewItem(String newItemCaption) {
Object itemId = getContainerDataSource().addEntity(new Trigger(newItemCaption, ""));
fireItemSetChange();
triggerSelector.setValue(itemId);
}
}
);
}
@Override
public TriggerContainer getContainerDataSource() {
return (TriggerContainer) super.getContainerDataSource();
}
};
com.vaadin.ui.Select
String newFilter;
if ((newFilter = (String) variables.get("filter")) != null) {
// this is a filter request
currentPage = ((Integer) variables.get("page")).intValue();
filterstring = newFilter;
if (filterstring != null) {
filterstring = filterstring.toLowerCase();
}
optionRepaint();
} else if (isNewItemsAllowed()) {
// New option entered (and it is allowed)
final String newitem = (String) variables.get("newitem");
if (newitem != null && newitem.length() > 0) {
getNewItemHandler().addNewItem(newitem); <- Handler call
// rebuild list
filterstring = null;
prevfilterstring = null;
}
}