I have Vaadin Combo Box with below items
Application
Federation
Innovation
When the user selects Application from the dropdown box I need to set APP in the similar way
Federation - FED
Innovation - INV
So when I fetch the need only short code of it not the entire name. How to achieve that?.
This basic case you can do like this:
ComboBox cb = new ComboBox();
cb.addItem("FED");
cb.setItemCaption("FED", "Federation");
cb.addItem("INV");
cb.setItemCaption("INV", "Innovation");
main.addComponent(cb);
// to show the value:
cb.setImmediate(true); // update the label immediatly
Label selected = new Label(cb);
main.addComponent(selected);
But I really recommend you get to know Items and Properties in Vaadin. Each selection in the ComboBox (and many other components in Vaadin) is an Item that can have any number of properties. You could show any of those properties as item caption in the ComboBox.
See the book for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With