From: Marko Grönroos Date: Tue, 20 May 2008 12:00:14 +0000 (+0000) Subject: Validator test code for manual. X-Git-Tag: 6.7.0.beta1~4729 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e7656fb835e81eee09b3bd28afa8a74e20be5b4b;p=vaadin-framework.git Validator test code for manual. svn changeset:4565/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java b/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java index a5625e91e1..015c5384c0 100644 --- a/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java +++ b/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java @@ -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("" + examples[i] + "", 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 is mightier than ."; + int pos = 0; + while (pos < fillintext.length()) { + int nexttag = fillintext.indexOf("<", pos); + if (nexttag == -1) { + + } + } + } + } } diff --git a/src/com/itmill/toolkit/tests/magi/SSNField.java b/src/com/itmill/toolkit/tests/magi/SSNField.java index 0d52da04f8..d3042180cb 100644 --- a/src/com/itmill/toolkit/tests/magi/SSNField.java +++ b/src/com/itmill/toolkit/tests/magi/SSNField.java @@ -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"); } } }