The property id must not be already used in the form.
This field is added to the layout using the {@link #attachField(Object,Field)} method.
24252627282930313233
addComponent(tf); Form f = new Form(); TextField tf2 = new TextField("A field in a read only form"); tf2.setRequired(true); f.addField("Field-1", tf2); f.setReadOnly(true); addComponent(f); } }
2829303132333435363738
final TextField requiredFieldWithError = new TextField( "Field with requiredError"); requiredFieldWithError.setRequired(true); requiredFieldWithError .setRequiredError("Error message for required field"); form.addField("field1", requiredFieldWithError); final TextField requiredFieldNoError = new TextField( "Field without requiredError"); requiredFieldNoError.setRequired(true); form.addField("field2", requiredFieldNoError);
3334353637383940414243
form.addField("field1", requiredFieldWithError); final TextField requiredFieldNoError = new TextField( "Field without requiredError"); requiredFieldNoError.setRequired(true); form.addField("field2", requiredFieldNoError); final TextField requiredFieldDescriptionAndError = new TextField( "Field with requiredError and description"); requiredFieldDescriptionAndError.setRequired(true); requiredFieldDescriptionAndError
4243444546474849505152
requiredFieldDescriptionAndError.setRequired(true); requiredFieldDescriptionAndError .setRequiredError("Error message for required field"); requiredFieldDescriptionAndError .setDescription("Description message for the field"); form.addField("field3", requiredFieldDescriptionAndError); main.addComponent(form); } }
3637383940414243444546
} private Form buildForm(String caption, boolean withError, boolean withFooter) { Form form = new Form(); form.setCaption(caption); form.addField("value", new TextField("MyField")); if (withError) { form.setComponentError(new UserError("Has error")); }
3839404142434445464748
TextField tf = new TextField("A field, must contain 1-2 chars"); tf.addValidator(new StringLengthValidator("Invalid length", 1, 2, false)); tf.setRequired(true); tf.setValue("ab"); form.addField("a", tf); tf = new TextField("A field, must contain an integer"); tf.addValidator(new IntegerValidator("Invalid integer {0}")); tf.setRequired(true); tf.setValue("123");
4445464748495051525354
tf = new TextField("A field, must contain an integer"); tf.addValidator(new IntegerValidator("Invalid integer {0}")); tf.setRequired(true); tf.setValue("123"); form.addField("b", tf); tf = new TextField("A field, must contain an integer or be empty"); tf.addValidator(new IntegerValidator("Invalid integer {0}")); tf.setValue("-321"); form.addField("c", tf);
4950515253545556575859
form.addField("b", tf); tf = new TextField("A field, must contain an integer or be empty"); tf.addValidator(new IntegerValidator("Invalid integer {0}")); tf.setValue("-321"); form.addField("c", tf); tf = new TextField( "A field, must contain a floating point number or be empty"); tf.addValidator(new DoubleValidator("Invalid double {0}")); tf.setValue("-123.45e6");
5556575859606162636465
tf = new TextField( "A field, must contain a floating point number or be empty"); tf.addValidator(new DoubleValidator("Invalid double {0}")); tf.setValue("-123.45e6"); form.addField("d", tf); tf = new TextField( "A field, must contain an e-mail address or be empty"); tf.addValidator(new EmailValidator("Invalid e-mail address {0}")); tf.setValue("a.b@example.com");
6162636465666768697071
tf = new TextField( "A field, must contain an e-mail address or be empty"); tf.addValidator(new EmailValidator("Invalid e-mail address {0}")); tf.setValue("a.b@example.com"); form.addField("e", tf); // regular expressions tf = new TextField("A field, must match the regular expression a.*b.*c"); tf.addValidator(new RegexpValidator("a.*b.*c",