Search in sources :

Example 6 with EventContext

use of org.apache.tapestry5.EventContext 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 7 with EventContext

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

the class PageRenderRequestHandlerImplTest method loopback_request.

@Test
public void loopback_request() throws Exception {
    RequestPageCache cache = mockRequestPageCache();
    ComponentEventResultProcessor processor = mockComponentEventResultProcessor();
    PageResponseRenderer renderer = mockPageResponseRenderer();
    Page page = mockPage();
    EventContext context = mockEventContext();
    ComponentPageElement root = mockComponentPageElement();
    InternalComponentResources pageResources = mockInternalComponentResources();
    PageActivator activator = newMock(PageActivator.class);
    Request request = mockRequest();
    train_getAttribute(request, InternalConstants.BYPASS_ACTIVATION, null);
    train_get(cache, "foo/Bar", page);
    train_getRootElement(page, root);
    train_getComponentResources(root, pageResources);
    expect(activator.activatePage(pageResources, context, processor)).andReturn(false);
    // Skips the pageReset()
    renderer.renderPageResponse(page);
    replay();
    PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, processor, renderer, activator, request);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("foo/Bar", context, true);
    handler.handle(parameters);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentEventResultProcessor(org.apache.tapestry5.services.ComponentEventResultProcessor) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) Request(org.apache.tapestry5.http.services.Request) PageRenderRequestHandler(org.apache.tapestry5.services.PageRenderRequestHandler) Page(org.apache.tapestry5.internal.structure.Page) Test(org.testng.annotations.Test)

Example 8 with EventContext

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

the class ComponentEventLinkEncoderImpl method createComponentEventLink.

public Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm) {
    StringBuilder builder = new StringBuilder(BUFFER_SIZE);
    // Build up the absolute URI.
    String activePageName = parameters.getActivePageName();
    String containingPageName = parameters.getContainingPageName();
    String eventType = parameters.getEventType();
    String nestedComponentId = parameters.getNestedComponentId();
    boolean hasComponentId = InternalUtils.isNonBlank(nestedComponentId);
    builder.append(contextPath);
    encodeAppFolderAndLocale(builder);
    builder.append(SLASH);
    builder.append(activePageName.toLowerCase());
    if (hasComponentId) {
        builder.append('.');
        builder.append(nestedComponentId);
    }
    if (!hasComponentId || !eventType.equals(EventConstants.ACTION)) {
        builder.append(':');
        builder.append(encodePageName(eventType));
    }
    appendContext(true, parameters.getEventContext(), builder);
    Link result = new LinkImpl(builder.toString(), forForm, requestSecurityManager.checkPageSecurity(activePageName), response, contextPathEncoder, baseURLSource);
    EventContext pageActivationContext = parameters.getPageActivationContext();
    if (pageActivationContext.getCount() != 0) {
        // Reuse the builder
        builder.setLength(0);
        appendContext(true, pageActivationContext, builder);
        // Omit that first slash
        result.addParameter(InternalConstants.PAGE_CONTEXT_NAME, builder.substring(1));
    }
    if (!containingPageName.equalsIgnoreCase(activePageName))
        result.addParameter(InternalConstants.CONTAINER_PAGE_NAME, encodePageName(containingPageName));
    return result;
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 9 with EventContext

use of org.apache.tapestry5.EventContext 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 10 with EventContext

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

the class UnknownActivationContextHandlerImpl method handleUnknownContext.

public void handleUnknownContext(ComponentResources pageResources, EventContext activationContext) throws IOException {
    logger.warn("Activate event on page {} was fired with context {} but was not handled", pageResources.getPage().getClass(), activationContext);
    String message = String.format("Activation context %s unrecognized for page %s", activationContext, pageResources.getPage().getClass());
    resultProcessor.processResultValue(new HttpError(HttpServletResponse.SC_NOT_FOUND, message));
}
Also used : HttpError(org.apache.tapestry5.services.HttpError)

Aggregations

EventContext (org.apache.tapestry5.EventContext)16 Test (org.testng.annotations.Test)15 Logger (org.slf4j.Logger)9 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)8 Link (org.apache.tapestry5.http.Link)8 ComponentModel (org.apache.tapestry5.model.ComponentModel)8 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)8 Page (org.apache.tapestry5.internal.structure.Page)5 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)5 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)4 AbstractEventContext (org.apache.tapestry5.internal.AbstractEventContext)3 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)3 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)3 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)3 Request (org.apache.tapestry5.http.services.Request)2 PageRenderLinkSource (org.apache.tapestry5.services.PageRenderLinkSource)2 IOException (java.io.IOException)1