Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Vaadin Combo Box I need to display one value and set another value

Tags:

vaadin

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?.

like image 608
Kalyan Raju Avatar asked Dec 17 '22 16:12

Kalyan Raju


1 Answers

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.

like image 101
Marc Englund Avatar answered Dec 31 '22 14:12

Marc Englund