diff options
-rw-r--r-- | vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java | 24 |
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; |