Search in sources :

Example 1 with ListenerInvocationNotAllowedException

use of org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException in project wicket by apache.

the class FormSubmitTest method submitDisabledOuterForm.

/**
 */
@Test
public void submitDisabledOuterForm() {
    outerForm.setEnabled(false);
    assertEnabledState(false, true, true);
    FormTester formTester = tester.newFormTester("outerForm");
    try {
        formTester.submit("submit");
        fail("Executing the listener on disabled component is not allowed.");
    } catch (ListenerInvocationNotAllowedException expected) {
        ;
    }
    assertOnSubmitCalled(false, false, false);
    assertOnErrorCalled(false, false, false);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) ListenerInvocationNotAllowedException(org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException) Test(org.junit.Test)

Example 2 with ListenerInvocationNotAllowedException

use of org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException in project wicket by apache.

the class FormTesterTest method noParametersCreatedForDisabledComponents.

/**
 * @throws Exception
 */
@Test
public void noParametersCreatedForDisabledComponents() throws Exception {
    tester.startPage(new MockFormPage() {

        private static final long serialVersionUID = -3023635650340910221L;

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            // on first rendering there can't be any form parameters.
            // on second rendering there must not be any since we disable the form.
            // the components all get rendered as disabled, so the browser would not send
            // any parameters. thus FormTester must not send any either.
            assertTrue(getRequest().getPostParameters().getParameterNames().isEmpty());
        }
    });
    final Component form = tester.getComponentFromLastRenderedPage("form");
    form.setEnabled(false);
    assertFalse(form.isEnabled());
    Component check = tester.getComponentFromLastRenderedPage("form:checkbox");
    assertTrue(check.isEnabled());
    assertFalse(check.isEnabledInHierarchy());
    FormTester formTester = tester.newFormTester("form");
    try {
        formTester.submit();
        fail("Executing the listener on disabled component is not allowed.");
    } catch (ListenerInvocationNotAllowedException expected) {
    // expected
    }
}
Also used : ListenerInvocationNotAllowedException(org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException) Component(org.apache.wicket.Component) Test(org.junit.Test)

Example 3 with ListenerInvocationNotAllowedException

use of org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException in project wicket by apache.

the class RequestListenerInterface method invoke.

/**
 * Invokes a given interface on a component.
 *
 * @param rcomponent
 *            The component
 *
 * @throws ListenerInvocationNotAllowedException
 *             when listener invocation attempted on a component that does not allow it
 */
public final void invoke(final IRequestableComponent rcomponent) {
    // we are in Wicket core land
    final Component component = (Component) rcomponent;
    if (!component.canCallListener()) {
        // just return so that we have a silent fail and just re-render the
        // page
        log.info("component not enabled or visible; ignoring call. Component: " + component);
        throw new ListenerInvocationNotAllowedException(component, null, "Component rejected interface invocation");
    }
    internalInvoke(component, component);
}
Also used : ListenerInvocationNotAllowedException(org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent)

Example 4 with ListenerInvocationNotAllowedException

use of org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException in project wicket by apache.

the class RequestListenerInterface method invoke.

/**
 * Invokes a given interface on a component's behavior.
 *
 * @param rcomponent
 *            The component
 * @param behavior
 * @throws ListenerInvocationNotAllowedException
 *             when listener invocation attempted on a component that does not allow it
 */
public final void invoke(final IRequestableComponent rcomponent, final Behavior behavior) {
    // we are in Wicket core land
    final Component component = (Component) rcomponent;
    if (!behavior.canCallListener(component)) {
        log.warn("behavior not enabled; ignore call. Behavior {} at component {}", behavior, component);
        throw new ListenerInvocationNotAllowedException(component, behavior, "Behavior rejected interface invocation. ");
    }
    internalInvoke(component, behavior);
}
Also used : ListenerInvocationNotAllowedException(org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent)

Aggregations

ListenerInvocationNotAllowedException (org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException)4 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)2 Test (org.junit.Test)2 Component (org.apache.wicket.Component)1 FormTester (org.apache.wicket.util.tester.FormTester)1