开发者

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

I have Vaadin Combo Box with below items

A开发者_运维百科pplication
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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜