Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
Button submit = new Button("submit") {
    public void onSubmit() {
        // handle form submission
    }
}
form.add(submit);

TextField foo = new TextField("foo") {
    public boolean isRequired() {
        Form form = (Form) findParent(Form.class);
        return form.getRootForm().findSubmittingButton() == submitButtonbutton;
    }
}
form.add(foo);

Note the call to getRootForm. Technically, this is only required in nested forms.

...

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"
class InternalForm<T> extends Form<T> implements IFormVisitorParticipant {
    public InternalForm(String name) {
        super(name);
    }

    public InternalForm(String name, IModel<T> model) {
     @Override   super(name, model);
    }

    public boolean isEnabledprocessChildren() {
        IFormSubmittingComponent submitter return= getRootForm().findSubmittingButton();
        if (submitter == null)
            return false;
        
        return submitter.getForm() == this;
    }
}

Form nestedForm = new InternalForm("nestedForm");