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

11,527

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.

Share:
11,527
Kalyan Raju
Author by

Kalyan Raju

Coding is fun. I would like to have fun always.

Updated on June 11, 2022

Comments

  • Kalyan Raju
    Kalyan Raju almost 2 years

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