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;
}
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();
}
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();
}
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();
}
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();
}
Aggregations