user3567657
user3567657

Reputation: 101

vaadin combobox addItem and option value(?)

code

       ComboBox combo = new ComboBox('comboBox');
       combo.addItem("A");
       combo.addItem("B");
       combo.addItem("C");
       combo.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {

            com.vaadin.data.Property changedProeprty = event.getProperty();
            String value = changedProeprty.toString() ;
        }
    });

value is 'C'

However I want to input the other value, like selectBox's option in html

      <select>
         <option value="1">A</option>
         <option value="2">B</option>
         <option value="3">C</option>
       </select>

How to input the option value and how to get the option value in vaadin combobox ?

Upvotes: 1

Views: 851

Answers (1)

Andr&#233; Schild
Andr&#233; Schild

Reputation: 4754

You have to set the "real" value as the items in your ComboBox. You can then use the setItemCaption(...) method to tell the system what do display in the UI.

// Set item caption for this item explicitly
select.addItem(2);
select.setItemCaption(2, "Demos");

Look in the book of vaadin for more details here

Upvotes: 2

Related Questions