Search in sources :

Example 1 with EventContext

use of org.apache.tapestry5.EventContext 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 EventContext

use of org.apache.tapestry5.EventContext 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 EventContext

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

the class ComponentEventImplTest method matches_on_event_type.

@Test
public void matches_on_event_type() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_getCount(context, 0);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, null, false, model, logger);
    assertTrue(event.matches("eventType", "someId", 0));
    assertFalse(event.matches("foo", "someId", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 4 with EventContext

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

the class ComponentEventImplTest method matches_on_component_id.

@Test
public void matches_on_component_id() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_getCount(context, 0);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, null, false, model, logger);
    assertTrue(event.matches("eventType", "someId", 0));
    assertFalse(event.matches("eventtype", "bar", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 5 with EventContext

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

the class ComponentEventImplTest method coerce_context.

@Test
public void coerce_context() {
    ComponentEventCallback handler = mockComponentEventHandler();
    ComponentPageElementResources resources = mockComponentPageElementResources();
    EventContext context = mockEventContext();
    Integer value = new Integer(27);
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_toClass(resources, "java.lang.Integer", Integer.class);
    train_getCount(context, 2);
    train_get(context, Integer.class, 0, value);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
    assertSame(event.coerceContext(0, "java.lang.Integer"), value);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentPageElementResources(org.apache.tapestry5.internal.structure.ComponentPageElementResources) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Aggregations

EventContext (org.apache.tapestry5.EventContext)16 Test (org.testng.annotations.Test)15 Logger (org.slf4j.Logger)9 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)8 Link (org.apache.tapestry5.http.Link)8 ComponentModel (org.apache.tapestry5.model.ComponentModel)8 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)8 Page (org.apache.tapestry5.internal.structure.Page)5 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)5 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)4 AbstractEventContext (org.apache.tapestry5.internal.AbstractEventContext)3 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)3 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)3 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)3 Request (org.apache.tapestry5.http.services.Request)2 PageRenderLinkSource (org.apache.tapestry5.services.PageRenderLinkSource)2 IOException (java.io.IOException)1