Versions Compared

Key

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

...

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;
    }
};

In Wicket 1.5 you have to do this (otherwise you'll get a null pointer)

Code Block

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

Another way is to let your child form implement IFormVisitorParticipant as follows:

Code Block
class InternalForm<T> extends Form<T> implements IFormVisitorParticipant {
    public InternalForm(String name) {
        super(name);
    }

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

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

Form nestedForm = new InternalForm("nestedForm");