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.
How do you give ComoboBox a Property (similar to TextField)
I like how I can force a TextField to be essentially a NumberField by giving it a Property, like so
final Property<Long> property = new ObjectProperty<Long>(42);
final TextField tf = new TextField("SomeNumber", property);
Now, if I want to get the value of the TextField as a Long, instead of calling tf.getValue() and then converting the String into a Long manually, which I think is very ugly, I can just call
long value = property.getValue();
I want to the same thing with ComboBox. I initialize the ComboBox with a bunch of Longs.
Long ns = {10000000L, 25000000L, 50000000L, 75000000L, 100000000L};
List<Long> options = Arrays.asList(ns);
final ComboBox cb = new ComboBox("SomeNumbers", options);
Say the user picks a value in the comboBox. When I call cb.getValue(), I get back a Long. So far, so good.
But, I also want the ComboBox to be editable so that I can type in a new number if I want. So I add the following.
cb.setTextInputAllowed(true);
cb.setNewItemsAllowed(true);
Now, if I type in a new number into the comboBox, cb.getValue() returns me a String. I need to manually convert the String into a Long, which is something I'm trying to avoid.
So, is there a way to force the ComboBox to be of type Long? The end result is that I want something that'd let me do
long cbValue = <SOMETHING>.getValue()