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

I have a Vaadin Combo Box with the following items

Application Federation Innovation 

When the user selects the application from the drop-down list, I need to install APP in the same way

 Federation - FED Innovation - INV 

Therefore, when I get only a short code, this is not a full name. How to achieve this?

+4
source share
1 answer

In this basic case, you can do the following:

 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 that you become familiar with objects and properties in Vaadin. Each choice in ComboBox (and many other components in Vaadin) is an element that can have any number of properties. You can show any of these properties as the title of an element in a ComboBox.

See the book for more details.

+12
source

Source: https://habr.com/ru/post/1342105/


All Articles