Search in sources :

Example 1 with TestItem

use of com.vaadin.flow.component.combobox.bean.TestItem in project flow-components by vaadin.

the class DataProviderPage method createDataProviderWithoutGetId.

private void createDataProviderWithoutGetId() {
    add(new Hr());
    ComboBox<TestItem> comboBoxWithoutGetId = new ComboBox<>();
    comboBoxWithoutGetId.setId(COMBO_BOX_WITHOUT_GET_ID_ID);
    comboBoxWithoutGetId.setItems(list);
    add(comboBoxWithoutGetId);
    NativeButton setValueUsingReferenceButton = new NativeButton("Set Value Using Reference", event -> comboBoxWithoutGetId.setValue(list.get(1)));
    setValueUsingReferenceButton.setId(SET_VALUE_USING_REFERENCE_BUTTON_ID);
    add(setValueUsingReferenceButton);
    NativeButton setValueUsingEqualsButton = new NativeButton("Set Value Using Equals", event -> comboBoxWithoutGetId.setValue(new TestItem(4, "c", "")));
    setValueUsingEqualsButton.setId(SET_VALUE_USING_EQUALS_BUTTON_ID);
    add(setValueUsingEqualsButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Hr(com.vaadin.flow.component.html.Hr) TestItem(com.vaadin.flow.component.combobox.bean.TestItem)

Example 2 with TestItem

use of com.vaadin.flow.component.combobox.bean.TestItem in project flow-components by vaadin.

the class DataProviderPage method createDataProviderWithGetId.

private void createDataProviderWithGetId() {
    ComboBox<TestItem> comboBoxWithGetId = new ComboBox<>();
    comboBoxWithGetId.setId(COMBO_BOX_WITH_GET_ID_ID);
    comboBoxWithGetId.setDataProvider(new ListDataProvider<TestItem>(list) {

        @Override
        public Object getId(TestItem item) {
            return item.getId();
        }
    });
    add(comboBoxWithGetId);
    NativeButton setValueUsingIdButton = new NativeButton("Set Value Using Id", event -> comboBoxWithGetId.setValue(new TestItem(2)));
    setValueUsingIdButton.setId(SET_VALUE_USING_GET_ID_BUTTON_ID);
    add(setValueUsingIdButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox) TestItem(com.vaadin.flow.component.combobox.bean.TestItem)

Example 3 with TestItem

use of com.vaadin.flow.component.combobox.bean.TestItem in project flow-components by vaadin.

the class RequiredComboboxPage method requiredComboBoxSetItemsAfter.

private void requiredComboBoxSetItemsAfter() {
    Binder<TestItem> binder = new Binder<>();
    ComboBox<String> comboBox = new ComboBox<>();
    binder.forField(comboBox).asRequired().bind(TestItem::getName, TestItem::setName);
    binder.setBean(new TestItem(0));
    // Set items last:
    comboBox.setItems("foo", "bar");
    add(comboBox);
}
Also used : Binder(com.vaadin.flow.data.binder.Binder) ComboBox(com.vaadin.flow.component.combobox.ComboBox) TestItem(com.vaadin.flow.component.combobox.bean.TestItem)

Aggregations

ComboBox (com.vaadin.flow.component.combobox.ComboBox)3 TestItem (com.vaadin.flow.component.combobox.bean.TestItem)3 NativeButton (com.vaadin.flow.component.html.NativeButton)2 Hr (com.vaadin.flow.component.html.Hr)1 Binder (com.vaadin.flow.data.binder.Binder)1