blob: 824c58436f89fa77ec751faddf5cb850ab686bba (
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
|
package com.vaadin.tests.tickets;
import java.util.Iterator;
import java.util.LinkedList;
import com.vaadin.data.Validator;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;
public class Ticket1811 extends com.vaadin.Application.LegacyApplication {
LinkedList<TextField> listOfAllFields = new LinkedList<TextField>();
@Override
public void init() {
final LegacyWindow main = new LegacyWindow("#1811");
setMainWindow(main);
Validator strLenValidator = new StringLengthValidator(
"String must be at least 3 chars long and non-null", 3, -1,
false);
TextField tf1 = new TextField(
"Text field with default settings (required=false)");
listOfAllFields.add(tf1);
TextField tf2 = new TextField("Text field with required=true");
tf2.setRequired(true);
listOfAllFields.add(tf2);
TextField tf3 = new TextField(
"Text field with required=true and strlen >= 3");
tf3.setRequired(true);
tf3.addValidator(strLenValidator);
listOfAllFields.add(tf3);
TextField tf4 = new TextField(
"Text field with required=false (default) and strlen >= 3");
tf4.addValidator(strLenValidator);
listOfAllFields.add(tf4);
for (Iterator<TextField> i = listOfAllFields.iterator(); i.hasNext();) {
TextField tf = i.next();
main.addComponent(tf);
tf.setImmediate(true);
}
Button checkValidity = new Button("Check validity of the fields");
main.addComponent(checkValidity);
checkValidity.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
StringBuffer msg = new StringBuffer();
for (Iterator<TextField> i = listOfAllFields.iterator(); i
.hasNext();) {
TextField tf = i.next();
msg.append("<h1>" + tf.getCaption() + "</h1>\n");
if (tf.isValid()) {
msg.append("VALID\n<hr/>");
} else {
msg.append("INVALID<br/><i>" + tf.getErrorMessage()
+ "</i><hr/>");
}
}
Window w = new Window("Status of the fields");
w.setModal(true);
w.addComponent(new Label(msg.toString(), ContentMode.XHTML));
main.addWindow(w);
}
});
}
}
|