Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public class DocumentType {
    private String name;
    private boolean hasExpiryDate;
    // getters and setters omitted
}

List<DocumentType> allDocumentTypes = ...;

final DropDownChoice ddc = new DropDownChoice("documentType", allDocumentTypes, new ChoiceRenderer("name"));
form.add(ddc);

TextField expiryDate = new TextField("expiryDate", Date.class) {
    public boolean isRequired() {
        DocumentType dt = (DocumentType) ddc.getConvertedInput();
        return dt != null && dt.getHasExpiryDate();
    }
}
form.add(expiryDate);

Isolating Nested Forms

Consider a nested form with its own submit button. When this button is clicked, only components on the nested form are validated. However, when a button on the parent form is clicked, components on both the parent form and the child form are validated.

Occasionally, you may want the forms to be truly independent, i.e. you want the parent form to not validate and submit the child form. This is easily done by overriding isEnabled() on the child form as follows:

Code Block

Form nestedForm = new Form("nestedForm") {
    @Override
    public boolean isEnabled() {
        return getRootForm().findSubmittingButton().getForm() == this;
    }
};