Search in sources :

Example 6 with Link

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

the class RequestSecurityManagerImpl method checkForInsecurePageRenderRequest.

public boolean checkForInsecurePageRenderRequest(PageRenderRequestParameters parameters) throws IOException {
    if (!needsRedirect(parameters.getLogicalPageName()))
        return false;
    // Page is secure but request is not, so redirect.
    Link link = componentEventLinkEncoder.createPageRenderLink(parameters);
    response.sendRedirect(link);
    return true;
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 7 with Link

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

the class RenderCommandComponentEventResultProcessor method renderMarkup.

/**
 * As a filter, this class does three things:
 * <ul>
 * <li>It creates an outer element to capture the partial page content that will be rendered</li>
 * <li>It does setup and cleanup with the {@link AjaxFormUpdateController}</li>
 * <li>It extracts the child markup and stuffs it into the reply's "content" property.</li>
 * </ul>
 */
public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
    // The partial will quite often contain multiple elements (or just a block of plain text),
    // so those must be enclosed in a root element.
    Element root = writer.element("ajax-partial");
    ajaxFormUpdateController.setupBeforePartialZoneRender(writer);
    renderer.renderMarkup(writer, reply);
    ajaxFormUpdateController.cleanupAfterPartialZoneRender();
    writer.end();
    String content = root.getChildMarkup().trim();
    reply.put("content", content);
}
Also used : Element(org.apache.tapestry5.dom.Element)

Example 8 with Link

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

the class ClientPersistentFieldStorageImplTest method null_value_is_a_remove.

@Test
public void null_value_is_a_remove() {
    Request request = mockRequest(null);
    Link link = mockLink();
    String pageName = "Foo";
    String componentId = "bar.baz";
    String fieldName = "woops";
    replay();
    ClientPersistentFieldStorage storage = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    storage.postChange(pageName, componentId, fieldName, 99);
    storage.postChange(pageName, componentId, fieldName, null);
    storage.updateLink(link);
    assertTrue(storage.gatherFieldChanges(pageName).isEmpty());
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 9 with Link

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

the class ClientPersistentFieldStorageImplTest method store_and_restore_a_change.

@SuppressWarnings("unchecked")
@Test
public void store_and_restore_a_change() {
    Request request = mockRequest(null);
    Link link = mockLink();
    String pageName = "Foo";
    String componentId = "bar.baz";
    String fieldName = "biff";
    Object value = 99;
    final Holder<String> holder = captureLinkModification(link);
    replay();
    ClientPersistentFieldStorage storage1 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    storage1.postChange(pageName, componentId, fieldName, value);
    List<PersistentFieldChange> changes1 = newList(storage1.gatherFieldChanges(pageName));
    storage1.updateLink(link);
    verify();
    assertEquals(changes1.size(), 1);
    PersistentFieldChange change1 = changes1.get(0);
    assertEquals(change1.getComponentId(), componentId);
    assertEquals(change1.getFieldName(), fieldName);
    assertEquals(change1.getValue(), value);
    // Now more training ...
    train_getParameter(request, ClientPersistentFieldStorageImpl.PARAMETER_NAME, holder.get());
    replay();
    ClientPersistentFieldStorage storage2 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    List<PersistentFieldChange> changes2 = newList(storage2.gatherFieldChanges(pageName));
    verify();
    assertEquals(changes2.size(), 1);
    PersistentFieldChange change2 = changes2.get(0);
    assertEquals(change2.getComponentId(), componentId);
    assertEquals(change2.getFieldName(), fieldName);
    assertEquals(change2.getValue(), value);
    assertNotSame(change1, change2);
}
Also used : Request(org.apache.tapestry5.http.services.Request) PersistentFieldChange(org.apache.tapestry5.services.PersistentFieldChange) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 10 with Link

use of org.apache.tapestry5.http.Link 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)

Aggregations

Link (org.apache.tapestry5.http.Link)66 Test (org.testng.annotations.Test)37 Response (org.apache.tapestry5.http.services.Response)19 MarkupWriter (org.apache.tapestry5.MarkupWriter)10 JSONObject (org.apache.tapestry5.json.JSONObject)10 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)10 Request (org.apache.tapestry5.http.services.Request)8 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)8 Element (org.apache.tapestry5.dom.Element)7 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)7 Link (org.apache.tapestry5.Link)6 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)6 EventContext (org.apache.tapestry5.EventContext)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 IOException (java.io.IOException)4 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)4 BaseURLSource (org.apache.tapestry5.http.services.BaseURLSource)4 Page (org.apache.tapestry5.internal.structure.Page)4 List (java.util.List)3 ComponentResources (org.apache.tapestry5.ComponentResources)3