"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));
}
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+"'."));
}
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.
}
}
});
// 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) {
+
+ }
+ }
+ }
+ }
}
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;
/* 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;
/** 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;
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. */
/* 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");
}
}
}