]> source.dussan.org Git - vaadin-framework.git/commitdiff
Validator test code for manual.
authorMarko Grönroos <magi@iki.fi>
Tue, 20 May 2008 12:00:14 +0000 (12:00 +0000)
committerMarko Grönroos <magi@iki.fi>
Tue, 20 May 2008 12:00:14 +0000 (12:00 +0000)
svn changeset:4565/svn branch:trunk

src/com/itmill/toolkit/tests/magi/MagiTestApplication.java
src/com/itmill/toolkit/tests/magi/SSNField.java

index a5625e91e1b0c919b8af2ae49e161c3db0bb37d8..015c5384c0c3cce2e7256ecdac97114d1765cde9 100644 (file)
@@ -106,9 +106,10 @@ public class MagiTestApplication extends com.itmill.toolkit.Application {
                     "alignment", "alignment/grid", "window", "window/opener",
                     "window/multiple", "classresource", "usererror",
                     "progress/window", "progress/thread", "progress",
-                    "customlayout", "spacing", "margin", "clientinfo"};
+                    "customlayout", "spacing", "margin", "clientinfo",
+                    "fillinform/templates"};
             for (int i = 0; i < examples.length; i++) {
-                main.addComponent(new Label("<a href='/tk5/testbench2/"
+                main.addComponent(new Label("<a href='/tk/testbench2/"
                         + examples[i] + "'>" + examples[i] + "</a>",
                         Label.CONTENT_XHTML));
             }
@@ -177,6 +178,8 @@ public class MagiTestApplication extends com.itmill.toolkit.Application {
             example_Margin(main, param);
         } else if (example.equals("clientinfo")) {
             example_ClientInfo(main, param);
+        } else if (example.equals("fillinform")) {
+            example_FillInForm(main, param);
         } else {
             ; // main.addComponent(new Label("Unknown test '"+example+"'."));
         }
@@ -403,12 +406,8 @@ public class MagiTestApplication extends com.itmill.toolkit.Application {
                 try {
                     // Validate the field value.
                     username.validate();
-
-                    // The value was ok, reset a possible error
-                    username.setComponentError(null);
                 } catch (final Validator.InvalidValueException e) {
-                    // The value was not ok. Set the error.
-                    username.setComponentError(new UserError(e.getMessage()));
+                    // The value was not ok. The error was set.
                 }
             }
         });
@@ -1150,4 +1149,31 @@ public class MagiTestApplication extends com.itmill.toolkit.Application {
         // Display the client identification string
         main.addComponent(new Label(browserApplication));
     }
+
+    void example_FillInForm(final Window main, String param) {
+       if (param.equals("templates")) {        
+               // Create a custom layout from the fill-in-form.html template.
+               CustomLayout fillinlayout = new CustomLayout("fill-in-form");
+       
+               // The style will set the display to be "inline".
+               fillinlayout.addStyleName("fillinlayout");
+       
+               // Create the fields that occur in the text.
+               TextField field1 = new TextField();
+               TextField field2 = new TextField();
+               fillinlayout.addComponent(field1, "q1");
+               fillinlayout.addComponent(field2, "q2");
+       
+               main.addComponent(fillinlayout);
+       } else {
+               String fillintext = "The <q1> is mightier than <q2>.";
+               int pos = 0;
+               while (pos < fillintext.length()) {
+                       int nexttag = fillintext.indexOf("<", pos);
+                       if (nexttag == -1) {
+                               
+                       }
+               }
+       }
+    }
 }
index 0d52da04f8480c2307ba2ecceb6e038da4b2c7a6..d3042180cb70c7404d9cff2f31f480041c4b83fe 100644 (file)
@@ -10,6 +10,7 @@ import com.itmill.toolkit.data.Property;
 import com.itmill.toolkit.data.Validator;
 import com.itmill.toolkit.data.Property.ValueChangeEvent;
 import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.FormLayout;
 import com.itmill.toolkit.ui.Label;
 import com.itmill.toolkit.ui.OrderedLayout;
 import com.itmill.toolkit.ui.TextField;
@@ -17,8 +18,8 @@ import com.itmill.toolkit.ui.TextField;
 /* Finnish Social Security Number input field that validates the value. */
 public class SSNField extends CustomComponent implements
         Property.ValueChangeListener {
-    OrderedLayout layout = new OrderedLayout(
-            OrderedLayout.ORIENTATION_HORIZONTAL);
+    OrderedLayout layout = new FormLayout();
+    // new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); //;new FormLayout();
     TextField myfield;
     Label myerror;
 
@@ -38,9 +39,11 @@ public class SSNField extends CustomComponent implements
         /** Validate the given SSN. */
         public void validate(Object value) throws InvalidValueException {
             final String ssn = (String) value;
-            if (ssn.length() != 11) {
+            if (ssn.length() == 0)
+               return;
+
+            if (ssn.length() != 11)
                 throw new InvalidValueException("Invalid SSN length");
-            }
 
             final String numbers = ssn.substring(0, 6) + ssn.substring(7, 10);
             final int checksum = new Integer(numbers).intValue() % 31;
@@ -54,21 +57,18 @@ public class SSNField extends CustomComponent implements
 
     SSNField() {
         setCompositionRoot(layout);
-        layout.setStyle("form");
+        layout.setOrientation(FormLayout.ORIENTATION_VERTICAL);
 
         /* Create the text field for the SSN. */
         myfield = new TextField("Social Security Number");
         myfield.setColumns(11);
-        myfield.setFormat(new MessageFormat("{0,number,##}"));
 
         /* Create and set the validator object for the field. */
         final SSNValidator ssnvalidator = new SSNValidator();
         myfield.addValidator(ssnvalidator);
 
-        /*
-         * ValueChageEvent will be generated immediately when the component
-         * loses focus.
-         */
+        /* ValueChageEvent will be generated immediately when the component
+           loses focus. */
         myfield.setImmediate(true);
 
         /* Listen for ValueChangeEvent events. */
@@ -88,16 +88,9 @@ public class SSNField extends CustomComponent implements
 
             /* The value was correct. */
             myerror.setValue("Ok");
-            myfield.setStyle("");
         } catch (final Validator.InvalidValueException e) {
             /* Report the error message to the user. */
             myerror.setValue(e.getMessage());
-
-            /*
-             * The CSS defines that text field with the "error" class will be
-             * colored red.
-             */
-            myfield.setStyle("error");
         }
     }
 }