blob: ac9f5f6df7740c4ff3820c2fc7104801e87eb829 (
plain)
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
49
50
51
52
53
54
|
package com.vaadin.tests.tickets;
import com.vaadin.LegacyApplication;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Validator;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.TextField;
public class Ticket2179 extends LegacyApplication {
TextField f = new TextField("Test fiel ( must contain 1 & 2 )");
LegacyWindow main = new LegacyWindow("Dual validator test");
@Override
public void init() {
f.setImmediate(true);
f.setRequired(true);
f.addValidator(new ContainsValidator("1"));
f.addValidator(new ContainsValidator("2"));
setMainWindow(main);
main.addComponent(f);
f.addListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
main.showNotification("Test field is "
+ (f.isValid() ? "valid" : "invalid"));
}
});
}
static class ContainsValidator implements Validator {
private final String c;
public ContainsValidator(String c) {
this.c = c;
}
@Override
public void validate(Object value) throws InvalidValueException {
if (value == null || !value.toString().contains(c)) {
throw new InvalidValueException("Value does not contain " + c);
}
}
}
}
|