Search in sources :

Example 1 with ArrayEventContext

use of org.apache.tapestry5.internal.services.ArrayEventContext 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;
}
Also used : ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) Page(org.apache.tapestry5.internal.structure.Page) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) Link(org.apache.tapestry5.http.Link)

Example 2 with ArrayEventContext

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

the class AppPageRenderLinkTransformer method decodePageRenderRequest.

public PageRenderRequestParameters decodePageRenderRequest(Request request) {
    String path = request.getPath();
    String[] split = path.substring(1).split("/");
    if (split.length == 1 && split[0].equals(""))
        return null;
    int pacx = 0;
    String possibleLocaleName = split[0];
    // Might be just the page activation context, or it might be locale then page
    // activation context
    boolean localeSpecified = localizationSetter.isSupportedLocaleName(possibleLocaleName);
    if (localeSpecified) {
        pacx++;
    }
    if (pacx >= split.length)
        return null;
    if (localeSpecified)
        localizationSetter.setLocaleFromLocaleName(possibleLocaleName);
    boolean isLoopback = request.getParameter(TapestryConstants.PAGE_LOOPBACK_PARAMETER_NAME) != null;
    return new PageRenderRequestParameters("View", new ArrayEventContext(typeCoercer, split[pacx]), isLoopback);
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ArrayEventContext(org.apache.tapestry5.internal.services.ArrayEventContext)

Example 3 with ArrayEventContext

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

the class StreamPageContentResultProcessor method processResultValue.

public void processResultValue(StreamPageContent value) throws IOException {
    Class<?> pageClass = value.getPageClass();
    Object[] activationContext = value.getPageActivationContext();
    final String pageName = pageClass == null ? requestGlobals.getActivePageName() : resolver.resolvePageClassNameToPageName(pageClass.getName());
    final EventContext context = activationContext == null ? new EmptyEventContext() : new ArrayEventContext(typeCoercer, activationContext);
    if (value.isBypassActivation()) {
        request.setAttribute(InternalConstants.BYPASS_ACTIVATION, true);
    }
    request.setAttribute(TapestryConstants.RESPONSE_RENDERER, new IOOperation<Void>() {

        public Void perform() throws IOException {
            handler.handle(new PageRenderRequestParameters(pageName, context, false));
            return null;
        }
    });
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) IOException(java.io.IOException)

Example 4 with ArrayEventContext

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

the class ComponentEventLinkEncoderImplTest method index_stripped_off.

@Test
public void index_stripped_off() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("admin/Index")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/admin/abc", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("admin/Index", new ArrayEventContext(typeCoercer, "abc"));
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 5 with ArrayEventContext

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

the class EventContextTests method array_event_context_to_strings.

@Test
public void array_event_context_to_strings() {
    EventContext ec = new ArrayEventContext(typeCoercer, 1, 2.3);
    assertEquals(ec.toStrings(), new String[] { "1", "2.3" });
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) Test(org.testng.annotations.Test)

Aggregations

Link (org.apache.tapestry5.http.Link)10 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)7 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)7 EventContext (org.apache.tapestry5.EventContext)6 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)6 Test (org.testng.annotations.Test)6 Page (org.apache.tapestry5.internal.structure.Page)4 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)4 RequestGlobals (org.apache.tapestry5.http.services.RequestGlobals)3 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)3 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)3 ArrayEventContext (org.apache.tapestry5.internal.services.ArrayEventContext)2 IOException (java.io.IOException)1 PageCallback (org.apache.tapestry5.PageCallback)1 Response (org.apache.tapestry5.http.services.Response)1 ContextPathEncoder (org.apache.tapestry5.services.ContextPathEncoder)1 PageRenderLinkSource (org.apache.tapestry5.services.PageRenderLinkSource)1