summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>2008-05-19 12:00:48 +0000
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>2008-05-19 12:00:48 +0000
commit6ebbf1553861b1dce7cb1d6470d09c84d8e9b19c (patch)
treee2d6696f26b675a441e3c3fef1674053c7d7331d /src/com
parenteed44a9b58be058723027b6a4bd73e275064fab6 (diff)
downloadvaadin-framework-6ebbf1553861b1dce7cb1d6470d09c84d8e9b19c.tar.gz
vaadin-framework-6ebbf1553861b1dce7cb1d6470d09c84d8e9b19c.zip
Added possibility to add form-level validators
svn changeset:4549/svn branch:trunk
Diffstat (limited to 'src/com')
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket736.java45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket736.java b/src/com/itmill/toolkit/tests/tickets/Ticket736.java
index 4410b63457..7a484aa343 100644
--- a/src/com/itmill/toolkit/tests/tickets/Ticket736.java
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket736.java
@@ -21,7 +21,7 @@ public class Ticket736 extends Application {
setMainWindow(mainWin);
// Create form for editing address
- Form f = new Form();
+ final Form f = new Form();
f.setItemDataSource(new BeanItem(address, new String[] { "name",
"street", "zip", "city", "state", "country" }));
f.setCaption("Office address");
@@ -68,6 +68,22 @@ public class Ticket736 extends Application {
}
}));
+ final AddressValidator av = new AddressValidator();
+ mainWin.addComponent(new Button("Add addressvalidator",
+ new Button.ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ f.addValidator(av);
+ }
+ }));
+ mainWin.addComponent(new Button("Remove addressvalidator",
+ new Button.ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ f.removeValidator(av);
+ }
+ }));
+
}
/** Address pojo. */
@@ -154,6 +170,33 @@ public class Ticket736 extends Application {
}
}
+ class AddressValidator implements Validator {
+
+ public boolean isValid(Object value) {
+ if (!(value instanceof Address)) {
+ return false;
+ }
+ Address a = (Address) value;
+ if (a.getCity() == null || ("" + a.getCity()).length() < 1) {
+ return false;
+ }
+ if (a.getStreet() == null || ("" + a.getStreet()).length() < 1) {
+ return false;
+ }
+ if (a.getZip() == null || ("" + a.getZip()).length() < 5) {
+ return false;
+ }
+ return true;
+ }
+
+ public void validate(Object value) throws InvalidValueException {
+ if (!isValid(value)) {
+ throw new InvalidValueException(
+ "Address should at least have street, zip and city set");
+ }
+ }
+ }
+
/** Simple state validator */
class IsValidState implements Validator {