use of org.apache.tapestry5.services.LinkCreationListener2 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.services.LinkCreationListener2 in project tapestry-5 by apache.
the class LinkSourceImplTest method testEventLinkCreation2.
private void testEventLinkCreation2(String pageName, String nestedId, String eventType, boolean forForm, Object... context) {
Page primaryPage = mockPage();
PageRenderQueue queue = mockPageRenderQueue();
PageActivationContextCollector collector = mockPageActivationContextCollector();
LinkCreationListener2 listener = mockLinkCreationListener2();
ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
Link link = mockLink();
ArrayEventContext eventContext = new ArrayEventContext(typeCoercer, context);
ArrayEventContext pageEventContext = new ArrayEventContext(typeCoercer, "a", "b");
train_getRenderingPage(queue, null);
train_getName(primaryPage, pageName);
train_collectPageActivationContext(collector, pageName, "a", "b");
ComponentEventRequestParameters parameters = new ComponentEventRequestParameters(pageName, pageName, nestedId, eventType, pageEventContext, eventContext);
expect(linkEncoder.createComponentEventLink(parameters, forForm)).andReturn(link);
listener.createdComponentEventLink(link, parameters);
List<LinkCreationListener2> configuration = CollectionFactory.newList(listener);
replay();
LinkSource source = new LinkSourceImpl(queue, collector, typeCoercer, null, linkEncoder, null, null, configuration);
Link returnedLink = source.createComponentEventLink(primaryPage, nestedId, eventType, forForm, context);
// Make sure the same link is returned.
assertSame(returnedLink, link);
verify();
}
use of org.apache.tapestry5.services.LinkCreationListener2 in project tapestry-5 by apache.
the class LinkSourceImplTest method testPageLinkCreation.
private void testPageLinkCreation(String pageName, boolean overrideContext, Object... context) {
PageActivationContextCollector collector = mockPageActivationContextCollector();
LinkCreationListener2 listener = mockLinkCreationListener2();
ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
Link link = mockLink();
ComponentClassResolver resolver = mockComponentClassResolver();
String canonical = "CanonicalPageName";
RequestGlobals globals = mockRequestGlobals();
// Ensure that the loopback logic is off; loopback logic is fully tested via an
// integration test.
expect(globals.getActivePageName()).andReturn("someOtherPage");
train_canonicalizePageName(resolver, pageName, canonical);
if (!overrideContext)
train_collectPageActivationContext(collector, canonical, context);
PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), false);
expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
listener.createdPageRenderLink(link, parameters);
replay();
LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
source.getLinkCreationHub().addListener(listener);
Object[] passedContext = overrideContext ? context : new Object[0];
Link returnedLink = source.createPageRenderLink(pageName, overrideContext, passedContext);
assertSame(returnedLink, link);
verify();
}
use of org.apache.tapestry5.services.LinkCreationListener2 in project tapestry-5 by apache.
the class LinkSourceImpl method createPageRenderLink.
public Link createPageRenderLink(String pageName, boolean override, Object... pageActivationContext) {
// Resolve the page name to its canonical format (the best version for URLs). This also
// validates
// the page name.
String canonical = resolver.canonicalizePageName(pageName);
Object[] context = (override || pageActivationContext.length != 0) ? pageActivationContext : contextCollector.collectPageActivationContext(canonical);
boolean loopback = canonical.equals(requestGlobals.getActivePageName()) && pageCache.get(pageName).hasResetListeners();
PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), loopback);
Link link = linkEncoder.createPageRenderLink(parameters);
for (LinkCreationListener2 listener : listeners) listener.createdPageRenderLink(link, parameters);
return link;
}
use of org.apache.tapestry5.services.LinkCreationListener2 in project tapestry-5 by apache.
the class LinkSourceImplTest method testPageLinkCreation2.
private void testPageLinkCreation2(String pageName, boolean overrideContext, Object... context) {
PageActivationContextCollector collector = mockPageActivationContextCollector();
LinkCreationListener2 listener = mockLinkCreationListener2();
ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
Link link = mockLink();
ComponentClassResolver resolver = mockComponentClassResolver();
String canonical = "CanonicalPageName";
RequestGlobals globals = mockRequestGlobals();
// Ensure that the loopback logic is off; loopback logic is fully tested via an
// integration test.
expect(globals.getActivePageName()).andReturn("someOtherPage");
train_canonicalizePageName(resolver, pageName, canonical);
if (!overrideContext)
train_collectPageActivationContext(collector, canonical, context);
PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), false);
expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
listener.createdPageRenderLink(link, parameters);
replay();
LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
source.getLinkCreationHub().addListener(listener);
Object[] passedContext = overrideContext ? context : new Object[0];
Link returnedLink = source.createPageRenderLink(pageName, overrideContext, passedContext);
assertSame(returnedLink, link);
verify();
}
Aggregations