blob: dd1732023ba82aca0808dcddbe9926b726e97072 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
package com.vaadin.tests.validation;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.Validator;
import com.vaadin.data.validator.IntegerValidator;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.TextField;
public class ValidationOfRequiredEmptyFields extends TestBase {
private TextField tf;
private CheckBox requiredInput;
private TextField requiredErrorInput;
private Validator integerValidator = new IntegerValidator(
"Must be an integer");
private Validator stringLengthValidator = new StringLengthValidator(
"Must be 5-10 chars", 5, 10, false);
private CheckBox integerValidatorInput;
private CheckBox stringLengthValidatorInput;
@Override
protected void setup() {
requiredInput = new CheckBox("Field required");
requiredInput.setImmediate(true);
requiredInput.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
tf.setRequired((Boolean) requiredInput.getValue());
}
});
requiredErrorInput = new TextField("Required error message");
requiredErrorInput.setImmediate(true);
requiredErrorInput.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
tf.setRequiredError((String) requiredErrorInput.getValue());
}
});
integerValidatorInput = new CheckBox("Integer.parseInt validator");
integerValidatorInput.setImmediate(true);
integerValidatorInput.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if ((Boolean) integerValidatorInput.getValue()) {
tf.addValidator(integerValidator);
} else {
tf.removeValidator(integerValidator);
}
}
});
stringLengthValidatorInput = new CheckBox(
"stringLength.parseInt validator");
stringLengthValidatorInput.setImmediate(true);
stringLengthValidatorInput.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if ((Boolean) stringLengthValidatorInput.getValue()) {
tf.addValidator(stringLengthValidator);
} else {
tf.removeValidator(stringLengthValidator);
}
}
});
tf = new TextField();
tf.setImmediate(true);
requiredInput.setValue(false);
requiredErrorInput.setValue("");
integerValidatorInput.setValue(false);
stringLengthValidatorInput.setValue(false);
addComponent(requiredInput);
addComponent(requiredErrorInput);
addComponent(integerValidatorInput);
addComponent(stringLengthValidatorInput);
addComponent(tf);
}
@Override
protected String getDescription() {
return null;
}
@Override
protected Integer getTicketNumber() {
return 3851;
}
}
|