Search in sources :

Example 1 with ClassVisitFilter

use of org.apache.wicket.util.visit.ClassVisitFilter in project wicket by apache.

the class Form method callOnError.

/**
 * Calls onError on this {@link Form} and any enabled and visible nested form, if the respective
 * {@link Form} actually has errors.
 *
 * @param submitter
 */
protected void callOnError(IFormSubmitter submitter) {
    final Form<?> processingForm = findFormToProcess(submitter);
    if (submitter != null) {
        submitter.onError();
    }
    // invoke Form#onSubmit(..) going from innermost to outermost
    Visits.visitPostOrder(processingForm, new IVisitor<Form<?>, Void>() {

        @Override
        public void component(Form<?> form, IVisit<Void> visit) {
            if (!form.isEnabledInHierarchy() || !form.isVisibleInHierarchy()) {
                visit.dontGoDeeper();
                return;
            }
            if (form.hasError()) {
                form.onError();
            }
        }
    }, new ClassVisitFilter(Form.class));
}
Also used : ClassVisitFilter(org.apache.wicket.util.visit.ClassVisitFilter)

Example 2 with ClassVisitFilter

use of org.apache.wicket.util.visit.ClassVisitFilter in project wicket by apache.

the class Form method delegateSubmit.

/**
 * Called (by the default implementation of 'process') when all fields validated, the form was
 * updated and it's data was allowed to be persisted. It is meant for delegating further
 * processing to clients.
 * <p>
 * This implementation first finds out whether the form processing was triggered by a nested
 * IFormSubmittingComponent of this form. If that is the case, that component's
 * onSubmitBefore/AfterForm methods are called appropriately..
 * </p>
 * <p>
 * Regardless of whether a submitting component was found, the form's onSubmit method is called
 * next.
 * </p>
 *
 * @param submittingComponent
 *            the component that triggered this form processing, or null if the processing was
 *            triggered by something else (like a non-Wicket submit button or a javascript
 *            execution)
 */
protected void delegateSubmit(IFormSubmitter submittingComponent) {
    final Form<?> processingForm = findFormToProcess(submittingComponent);
    // collect all forms innermost to outermost before any hierarchy is changed
    final List<Form<?>> forms = Generics.newArrayList(3);
    Visits.visitPostOrder(processingForm, new IVisitor<Form<?>, Void>() {

        @Override
        public void component(Form<?> form, IVisit<Void> visit) {
            if (form.isSubmitted()) {
                forms.add(form);
            }
        }
    }, new ClassVisitFilter(Form.class));
    // process submitting component (if specified)
    if (submittingComponent != null) {
        // invoke submit on component
        submittingComponent.onSubmit();
    }
    // invoke Form#onSubmit(..)
    for (Form<?> form : forms) {
        form.onSubmit();
    }
    if (submittingComponent != null) {
        submittingComponent.onAfterSubmit();
    }
}
Also used : ClassVisitFilter(org.apache.wicket.util.visit.ClassVisitFilter)

Example 3 with ClassVisitFilter

use of org.apache.wicket.util.visit.ClassVisitFilter in project wicket by apache.

the class VisitorTest method testVisitParents.

/**
 * https://issues.apache.org/jira/browse/WICKET-3805
 *
 * Visit parents with arbitrary type
 */
@Test
public void testVisitParents() {
    TestContainer testContainer = new TestContainer();
    IVisitor<MarkupContainer, MarkerInterface> visitor = new IVisitor<MarkupContainer, MarkerInterface>() {

        @Override
        public void component(MarkupContainer object, IVisit<MarkerInterface> visit) {
            visit.stop((MarkerInterface) object);
        }
    };
    MarkerInterface markedParent = testContainer.get("G:H").visitParents(MarkupContainer.class, visitor, new ClassVisitFilter(MarkerInterface.class));
    assertEquals("G", markedParent.getId());
}
Also used : WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) IVisitor(org.apache.wicket.util.visit.IVisitor) ClassVisitFilter(org.apache.wicket.util.visit.ClassVisitFilter) IVisit(org.apache.wicket.util.visit.IVisit) Test(org.junit.Test)

Aggregations

ClassVisitFilter (org.apache.wicket.util.visit.ClassVisitFilter)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 IVisit (org.apache.wicket.util.visit.IVisit)1 IVisitor (org.apache.wicket.util.visit.IVisitor)1 Test (org.junit.Test)1