javacomboboxvaadinvaadin7

Vaadin combobox separator


I'm currently developing a Vaadin app, and I've arrived to the need of a ComboBox with some separators between items. I've been looking arround and it seems currently there is no way to achieve this.

Being more specific:

What I've tried so far:
I overwrote setInternalValue method of the ComboBox, to not be able to select a separator like this:

public class ComboBoxWithSeparators() {
    @Override
    protected void setInternalValue(Object newValue) {
        Object oldValue = super.getValue();
        if(isSeparator)
            super.setInternalValue(oldValue);
        else
            super.setInternalValue(newValue);
    }
}

This kinda works, but when you select a separator, it is shown by a fraction of a second in the selected box, then is overriden by the old element.
So, my actual question is: Is there a way to not enable selecting an item within the ComboBox?

Related: Add an item in ComboBox and disable it with JS


Solution

  • Currently there is no way to obtain such thing as a ComboBox with separators in Vaadin, but there are some workarounds that can be used instead of that:

    Vaadin Menu bar
    This component supports separators, categories and enabling/disabling items. The con is that it doesn't allow filtering like ComboBox, but you can add shortcuts for usual selections.

    The problem here is that you can actually select separators, but the #setInternalValue override will restore the old element. This may cause odd behaviour.