Search code examples
javacomboboxvaadin8

Why Vaadin 8 ComboBox is adding extra empty item


Why there is an empty item added in the ComboBox? How to get only 2 items? No extra empty item.

ComboBox<GroupType> typeSelect = new ComboBox<>();
typeSelect.setId("portfolioGroupTypeSelect");
typeSelect.setItems(GroupType.PortfolioGroup, GroupType.DynamicGroup);
//  HasCaption.fillTo(typeSelect, GroupType.class); I tried it as well
typeSelect.addValueChangeListener(new TypeSelectValueChanged());

public enum GroupType implements HasCaption {
    PortfolioGroup("PortfolioGroupsWindow.typeSelect.portfolioGroup"),
    DynamicGroup("PortfolioGroupsWindow.typeSelect.dynamicGroup");
    private final String key;
    GroupType(String key) {
        this.key = key;
    }

    @Override
    public String getCaption() {
        return SalkkuTM.getI18N(key);
    }
}

enter image description here


Solution

  • I found the solutions as:-

    typeSelect.setEmptySelectionAllowed(false);
    

    It removes the empty item. I found it right after posting the question.