summaryrefslogtreecommitdiffstats
path: root/vaadin-app/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-09-26 15:18:31 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-09-26 15:18:31 +0200
commit68daa4fa00300af31778e079b79ea825c12ac3be (patch)
tree79c315819492d773ddad5a24ad1f31bf8b2b2861 /vaadin-app/src/ch/asynk
parent518e05b52940b34063c434b055a52f248d4e680c (diff)
downloadskeletons-68daa4fa00300af31778e079b79ea825c12ac3be.zip
skeletons-68daa4fa00300af31778e079b79ea825c12ac3be.tar.gz
vaadin-app: implements Validator
Diffstat (limited to 'vaadin-app/src/ch/asynk')
-rw-r--r--vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java
index badf223..ec7ac94 100644
--- a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java
+++ b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java
@@ -14,6 +14,7 @@ import com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.data.Validator;
import com.vaadin.data.validator.DoubleValidator;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.VerticalLayout;
@@ -69,6 +70,29 @@ class DataMappingLayout extends FormLayout {
}
});
//
+ // final Validator intValidator = new Validator() { ... }
+ class MyIntValidator implements Validator {
+ public boolean isValid(Object value) {
+ if (value == null || !(value instanceof String)) {
+ return false;
+ }
+ return ((String) value).matches("[1-9][0-9]{4}");
+ }
+ public void validate(Object value) throws InvalidValueException {
+ if (!isValid(value)) {
+ if (value != null && value.toString().startsWith("0")) {
+ throw new InvalidValueException("Must not start with a zero.");
+ } else {
+ throw new InvalidValueException("Must be a number 10000-99999.");
+ }
+ }
+ }
+ };
+ final TextField tf5 = new TextField("MyIntValidator");
+ tf5.addValidator(new MyIntValidator());
+ tf5.setImmediate(true);
+ addComponent(tf5);
+ //
class IntegerObjectProperty implements Property {
Integer data = 0;
boolean readOnly = false;