diff options
-rw-r--r-- | vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java index 3dfe515..e69967d 100644 --- a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java +++ b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java @@ -44,7 +44,7 @@ class DataMappingLayout extends FormLayout { // Double trouble = 66.6; final ObjectProperty<Double> property = new ObjectProperty<Double>(trouble); - final TextField tf2 = new TextField("ObjectProperty", property); + final TextField tf2 = new TextField("ObjectProperty + Validator", property); tf2.setImmediate(true); tf2.addValidator( new DoubleValidator("It should be a double") ); //tf2.setValidationVisible(false); // nothing will happen @@ -53,6 +53,22 @@ class DataMappingLayout extends FormLayout { lb2.setCaption("The Value"); addComponent(lb2); // + final TextField tf3 = new TextField("No spaces"); + addComponent(tf3); + tf3.setComponentError(null); // (actually the default) + final Button b1 = new Button("Ok!"); + addComponent(b1); + b1.addListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + if (! ((String) tf3.getValue()).matches("^\\w*$")) { + tf3.setComponentError(new UserError("Must be letters and numbers")); + } else { + tf3.setComponentError(null); + } + } + }); + // Button closeButton = new Button("close the application"); closeButton.setDescription("This will close the application"); addComponent(closeButton ); |