This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
RequiredComboboxPage.java
48 lines (41 loc) · 1.7 KB
/
RequiredComboboxPage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright 2000-2018 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.component.combobox.test;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.combobox.bean.TestItem;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.Route;
@Route("required-combobox")
public class RequiredComboboxPage extends Div {
public RequiredComboboxPage() {
Div message = new Div();
message.setId("message");
Binder<TestItem> binder = new Binder<>();
ComboBox<String> comboBox = new ComboBox<>();
comboBox.setItems("foo", "bar");
comboBox.addValueChangeListener(event -> message
.setText(String.format("Value changed from '%s' to '%s'",
event.getOldValue(), event.getValue())));
binder.forField(comboBox).asRequired()
.withValidator(value -> !"foo".equals(value),
"'foo' is invalid value")
.bind(TestItem::getName, TestItem::setName);
TestItem item = new TestItem(0);
binder.setBean(item);
add(comboBox, message);
}
}