Search in sources :

Example 1 with PageRenderLinkSource

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

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

the class PageRenderLinkSourceImplTest method override_passivate_context.

@Test
public void override_passivate_context() {
    ComponentClassResolver resolver = mockComponentClassResolver();
    LinkSource source = mockLinkSource();
    Link link = mockLink();
    EventContext eventContext = mockEventContext();
    train_resolvePageClassNameToPageName(resolver, PAGE_CLASS.getName(), PAGE_NAME);
    expect(source.createPageRenderLink(PAGE_NAME, true, "fred", "barney")).andReturn(link);
    train_resolvePageClassNameToPageName(resolver, PAGE_CLASS.getName(), PAGE_NAME);
    train_getCount(eventContext, 2);
    train_get(eventContext, Object.class, 0, "ted");
    train_get(eventContext, Object.class, 1, "barney");
    expect(source.createPageRenderLink(PAGE_NAME, true, "ted", "barney")).andReturn(link);
    replay();
    PageRenderLinkSource service = new PageRenderLinkSourceImpl(source, resolver);
    assertSame(service.createPageRenderLinkWithContext(PAGE_CLASS, "fred", "barney"), link);
    assertSame(service.createPageRenderLinkWithContext(PAGE_CLASS, eventContext), link);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 3 with PageRenderLinkSource

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

the class PageRenderLinkSourceImplTest method default_passivate_context.

@Test
public void default_passivate_context() {
    ComponentClassResolver resolver = mockComponentClassResolver();
    LinkSource source = mockLinkSource();
    Link link = mockLink();
    train_resolvePageClassNameToPageName(resolver, PAGE_CLASS.getName(), PAGE_NAME);
    expect(source.createPageRenderLink(PAGE_NAME, false)).andReturn(link);
    replay();
    PageRenderLinkSource service = new PageRenderLinkSourceImpl(source, resolver);
    assertSame(service.createPageRenderLink(PAGE_CLASS), link);
    verify();
}
Also used : PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 4 with PageRenderLinkSource

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

the class PageCallbackTest method callback_with_no_context.

@Test
public void callback_with_no_context() {
    PageRenderLinkSource source = mockPageRenderLinkSource();
    Link link = mockLink();
    expect(source.createPageRenderLinkWithContext("foo")).andReturn(link);
    PageCallback pc = new PageCallback("foo");
    assertEquals(pc.toString(), "PageCallback[foo]");
    replay();
    assertSame(pc.toLink(source), link);
    verify();
}
Also used : PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) PageCallback(org.apache.tapestry5.PageCallback) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 5 with PageRenderLinkSource

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

the class PageCallbackTest method callback_with_context.

@Test
public void callback_with_context() {
    EventContext context = new ArrayEventContext(typeCoercer, 1, 2);
    PageRenderLinkSource source = mockPageRenderLinkSource();
    Link link = mockLink();
    expect(source.createPageRenderLinkWithContext("bar", "1", "2")).andReturn(link);
    PageCallback pc = new PageCallback("bar", context);
    assertEquals(pc.toString(), "PageCallback[bar 1/2]");
    replay();
    assertSame(pc.toLink(source), link);
    verify();
}
Also used : ArrayEventContext(org.apache.tapestry5.internal.services.ArrayEventContext) EventContext(org.apache.tapestry5.EventContext) ArrayEventContext(org.apache.tapestry5.internal.services.ArrayEventContext) PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) PageCallback(org.apache.tapestry5.PageCallback) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Aggregations

Link (org.apache.tapestry5.http.Link)4 PageRenderLinkSource (org.apache.tapestry5.services.PageRenderLinkSource)4 Test (org.testng.annotations.Test)4 EventContext (org.apache.tapestry5.EventContext)2 PageCallback (org.apache.tapestry5.PageCallback)2 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)2 PrintWriter (java.io.PrintWriter)1 Link (org.apache.tapestry5.Link)1 ArrayEventContext (org.apache.tapestry5.internal.services.ArrayEventContext)1