Search in sources :

Example 1 with ComponentEventRequestParameters

use of org.apache.tapestry5.services.ComponentEventRequestParameters in project tapestry-5 by apache.

the class LinkSourceImpl method createComponentEventLink.

public Link createComponentEventLink(Page page, String nestedId, String eventType, boolean forForm, Object... eventContext) {
    assert page != null;
    assert InternalUtils.isNonBlank(eventType);
    Page activePage = pageRenderQueue.getRenderingPage();
    // See TAPESTRY-2184
    if (activePage == null)
        activePage = page;
    String activePageName = activePage.getName();
    Object[] pageActivationContext = contextCollector.collectPageActivationContext(activePageName);
    ComponentEventRequestParameters parameters = new ComponentEventRequestParameters(activePageName, page.getName(), toBlank(nestedId), eventType, new ArrayEventContext(typeCoercer, pageActivationContext), new ArrayEventContext(typeCoercer, eventContext));
    Link link = linkEncoder.createComponentEventLink(parameters, forForm);
    for (LinkCreationListener2 listener : listeners) listener.createdComponentEventLink(link, parameters);
    return link;
}
Also used : ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) Page(org.apache.tapestry5.internal.structure.Page) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) Link(org.apache.tapestry5.http.Link)

Example 2 with ComponentEventRequestParameters

use of org.apache.tapestry5.services.ComponentEventRequestParameters in project tapestry-5 by apache.

the class ComponentEventDispatcherTest method test.

private void test(String requestPath, String localeName, String containerPageName, String nestedComponentId, String eventType, String... eventContext) throws IOException {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter localizationSetter = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters(containerPageName, containerPageName, nestedComponentId, eventType, new EmptyEventContext(), new URLEventContext(contextValueEncoder, eventContext));
    train_getPath(request, requestPath);
    expect(localizationSetter.isSupportedLocaleName(localeName)).andReturn(false);
    train_isPageName(resolver, containerPageName, true);
    train_canonicalizePageName(resolver, containerPageName, containerPageName);
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    handler.handleComponentEvent(expectedParameters);
    train_for_request_locale(request, localizationSetter);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, localizationSetter, response, null, null, null, true, null, "", metaDataLocator, null));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) URLEventContext(org.apache.tapestry5.internal.URLEventContext) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator)

Example 3 with ComponentEventRequestParameters

use of org.apache.tapestry5.services.ComponentEventRequestParameters in project tapestry-5 by apache.

the class ComponentEventDispatcherTest method different_active_and_containing_pages.

@Test
public void different_active_and_containing_pages() throws Exception {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters("activepage", "mypage", "", "eventname", new EmptyEventContext(), new EmptyEventContext());
    train_getPath(request, "/activepage:eventname");
    expect(ls.isSupportedLocaleName("activepage:eventname")).andReturn(false);
    train_isPageName(resolver, "activepage", true);
    train_canonicalizePageName(resolver, "activepage", "activepage");
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, "mypage");
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    train_canonicalizePageName(resolver, "mypage", "mypage");
    train_for_request_locale(request, ls);
    handler.handleComponentEvent(expectedParameters);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 4 with ComponentEventRequestParameters

use of org.apache.tapestry5.services.ComponentEventRequestParameters in project tapestry-5 by apache.

the class AjaxFilter method handle.

public void handle(ComponentEventRequestParameters parameters, ComponentEventRequestHandler handler) throws IOException {
    ComponentEventRequestHandler next = request.isXHR() ? ajaxHandler : handler;
    next.handle(parameters);
}
Also used : ComponentEventRequestHandler(org.apache.tapestry5.services.ComponentEventRequestHandler)

Example 5 with ComponentEventRequestParameters

use of org.apache.tapestry5.services.ComponentEventRequestParameters in project tapestry-5 by apache.

the class ComponentEventDispatcher method dispatch.

public boolean dispatch(Request request, Response response) throws IOException {
    ComponentEventRequestParameters parameters = linkEncoder.decodeComponentEventRequest(request);
    if (parameters == null)
        return false;
    // Inside this pipeline, may find that the component id does not exist (this check only occurs in production
    // mode) ...
    componentRequestHandler.handleComponentEvent(parameters);
    // ... in which case, this attribute is set.
    if (request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND) != null) {
        return false;
    }
    return true;
}
Also used : ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters)

Aggregations

ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)13 Link (org.apache.tapestry5.http.Link)7 Page (org.apache.tapestry5.internal.structure.Page)7 Request (org.apache.tapestry5.http.services.Request)6 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)6 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)6 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)6 Test (org.testng.annotations.Test)6 Response (org.apache.tapestry5.http.services.Response)5 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)4 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)4 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)3 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)3 TrackableComponentEventCallback (org.apache.tapestry5.TrackableComponentEventCallback)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 URLEventContext (org.apache.tapestry5.internal.URLEventContext)2 ComponentPageElement (org.apache.tapestry5.internal.structure.ComponentPageElement)2 ComponentEventRequestHandler (org.apache.tapestry5.services.ComponentEventRequestHandler)2 Locale (java.util.Locale)1