Search in sources :

Example 1 with RequestGlobals

use of org.apache.tapestry5.http.services.RequestGlobals in project flowlogix by flowlogix.

the class SessionTrackerUtil method redirectToSelf.

public static void redirectToSelf(RequestGlobals rg, PageRenderLinkSource linkSource) throws IOException {
    final Link link = linkSource.createPageRenderLink(rg.getRequest().getPath().replaceFirst("\\..*", "").substring(1));
    final String url = link.toAbsoluteURI(rg.getRequest().isSecure());
    if (rg.getRequest().isXHR()) {
        try (PrintWriter writer = rg.getResponse().getPrintWriter("application/json")) {
            writer.write("{\n\t\"redirectURL\" : \"" + url + "\"\n}");
        }
    } else {
        rg.getResponse().sendRedirect(url);
    }
}
Also used : Link(org.apache.tapestry5.Link) PrintWriter(java.io.PrintWriter)

Example 2 with RequestGlobals

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

the class ComponentSourceImplTest method get_active_page.

@Test
public void get_active_page() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    RequestGlobals globals = mockRequestGlobals();
    String pageName = "Active";
    expect(globals.getActivePageName()).andReturn(pageName);
    train_get(cache, pageName, page);
    train_getRootComponent(page, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, globals);
    assertSame(source.getActivePage(), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 3 with RequestGlobals

use of org.apache.tapestry5.http.services.RequestGlobals 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();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Link(org.apache.tapestry5.http.Link)

Example 4 with RequestGlobals

use of org.apache.tapestry5.http.services.RequestGlobals 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();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Link(org.apache.tapestry5.http.Link)

Example 5 with RequestGlobals

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

the class LinkSourceImplTest method create_page_render_link_by_name.

@Test
public void create_page_render_link_by_name() {
    String pageName = "order/Edit";
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ComponentClassResolver resolver = mockComponentClassResolver();
    RequestGlobals globals = mockRequestGlobals();
    expect(globals.getActivePageName()).andReturn("someOtherPage");
    train_canonicalizePageName(resolver, pageName, pageName);
    train_collectPageActivationContext(collector, pageName, 3);
    EventContext pageActivationContext = new ArrayEventContext(typeCoercer, 3);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(pageName, pageActivationContext, false);
    expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
    replay();
    LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
    Link actual = source.createPageRenderLink(pageName, false);
    // Make sure the same link is returned.
    assertEquals(actual, link);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Aggregations

RequestGlobals (org.apache.tapestry5.http.services.RequestGlobals)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)4 Link (org.apache.tapestry5.http.Link)3 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)3 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)3 Test (org.testng.annotations.Test)3 ComponentSource (org.apache.tapestry5.services.ComponentSource)2 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)2 PrintWriter (java.io.PrintWriter)1 EventContext (org.apache.tapestry5.EventContext)1 Link (org.apache.tapestry5.Link)1 Page (org.apache.tapestry5.internal.structure.Page)1 Component (org.apache.tapestry5.runtime.Component)1