Search in sources :

Example 1 with IRequestableComponent

use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.

the class ListenerRequestHandler 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
 */
private final void invoke(final IRequestCycle requestCycle, RedirectPolicy policy, boolean ajax, 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(requestCycle, policy, ajax, component, component);
}
Also used : Component(org.apache.wicket.Component) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent)

Example 2 with IRequestableComponent

use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.

the class ListenerRequestHandler method respond.

@Override
public void respond(final IRequestCycle requestCycle) {
    final IRequestablePage page = getPage();
    final boolean freshPage = pageComponentProvider.doesProvideNewPage();
    final boolean isAjax = ((WebRequest) requestCycle.getRequest()).isAjax();
    IRequestableComponent component;
    try {
        component = getComponent();
    } catch (ComponentNotFoundException e) {
        // either the page is stateless and the component we are looking for is not added in the
        // constructor
        // or the page is stateful+stale and a new instances was created by pageprovider
        // we denote this by setting component to null
        component = null;
    }
    if ((component == null && !freshPage) || (component != null && component.getPage() != page)) {
        throw new ComponentNotFoundException("Component '" + getComponentPath() + "' has been removed from page.");
    }
    if (page instanceof Page) {
        // initialize the page to be able to check whether it is stateless
        ((Page) page).internalInitialize();
    }
    RedirectPolicy policy = page.isPageStateless() ? RedirectPolicy.NEVER_REDIRECT : RedirectPolicy.AUTO_REDIRECT;
    boolean blockIfExpired = component != null && !component.canCallListenerAfterExpiry();
    boolean lateComponent = component == null && freshPage;
    if ((pageComponentProvider.wasExpired() && blockIfExpired) || lateComponent) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("An IRequestListener was called but its page/component({}) couldn't be resolved. " + "Scheduling re-create of the page and ignoring the listener interface...", getComponentPath());
        }
        if (isAjax) {
            policy = RedirectPolicy.ALWAYS_REDIRECT;
        }
        requestCycle.scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(new PageProvider(page), policy));
        return;
    }
    invokeListener(requestCycle, policy, isAjax);
}
Also used : RedirectPolicy(org.apache.wicket.core.request.handler.RenderPageRequestHandler.RedirectPolicy) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) WebRequest(org.apache.wicket.request.http.WebRequest) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Page(org.apache.wicket.Page) IRequestablePage(org.apache.wicket.request.component.IRequestablePage)

Example 3 with IRequestableComponent

use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.

the class ListenerRequestHandler 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
 */
private final void invoke(final IRequestCycle requestCycle, RedirectPolicy policy, boolean ajax, 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(requestCycle, policy, ajax, component, behavior);
}
Also used : Component(org.apache.wicket.Component) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent)

Example 4 with IRequestableComponent

use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.

the class BookmarkableMapperTest method encode7.

/**
 */
@Test
public void encode7() {
    MockPage page = new MockPage(15);
    page.getPageParameters().set(0, "i1");
    page.getPageParameters().set(1, "i2");
    page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
    page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
    // shouldn't make any difference for BookmarkableListenerRequestHandler,
    // as this explicitly says the url must be bookmarkable
    page.setCreatedBookmarkable(false);
    IRequestableComponent c = page.get("foo:bar");
    PageAndComponentProvider provider = new PageAndComponentProvider(page, c);
    IRequestHandler handler = new BookmarkableListenerRequestHandler(provider, 4);
    Url url = encoder.mapHandler(handler);
    assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15-0.4-foo-bar&a=b&b=c", url.toString());
}
Also used : IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 5 with IRequestableComponent

use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.

the class CryptoMapperTest method additionalParameters.

/**
 * Additional parameters, WICKET-4923
 */
@Test
public void additionalParameters() {
    MockPage page = new MockPage();
    IRequestableComponent c = page.get("foo:bar");
    PageAndComponentProvider provider = new PageAndComponentProvider(page, c);
    IRequestHandler handler = new ListenerRequestHandler(provider);
    Url url = mapper.mapHandler(handler);
    url.addQueryParameter("q", "foo");
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertThat(requestHandler, instanceOf(RequestSettingRequestHandler.class));
    assertEquals("foo", ((RequestSettingRequestHandler) requestHandler).getRequest().getUrl().getQueryParameterValue("q").toString());
}
Also used : IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) RequestSettingRequestHandler(org.apache.wicket.core.request.handler.RequestSettingRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)15 MockPage (org.apache.wicket.MockPage)10 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)10 IRequestHandler (org.apache.wicket.request.IRequestHandler)10 Url (org.apache.wicket.request.Url)10 Test (org.junit.Test)10 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)9 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)4 Component (org.apache.wicket.Component)2 ListenerInvocationNotAllowedException (org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException)2 Page (org.apache.wicket.Page)1 RedirectPolicy (org.apache.wicket.core.request.handler.RenderPageRequestHandler.RedirectPolicy)1 RequestSettingRequestHandler (org.apache.wicket.core.request.handler.RequestSettingRequestHandler)1 Request (org.apache.wicket.request.Request)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1 WebRequest (org.apache.wicket.request.http.WebRequest)1