Search in sources :

Example 11 with ComponentPageElement

use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.

the class InternalComponentResourcesImplTest method render_informal_parameters_skips_formal_parameters.

@Test
public void render_informal_parameters_skips_formal_parameters() {
    ComponentPageElement element = mockComponentPageElement();
    Component component = mockComponent();
    Instantiator ins = mockInstantiator(component);
    MarkupWriter writer = mockMarkupWriter();
    ComponentModel model = mockComponentModel();
    ParameterModel pmodel = mockParameterModel();
    Binding binding = mockBinding();
    train_getModel(ins, model);
    train_getParameterModel(model, "fred", pmodel);
    replay();
    InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, elementResources, null, null, ins, false);
    resources.bindParameter("fred", binding);
    resources.renderInformalParameters(writer);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) InternalPropBinding(org.apache.tapestry5.internal.bindings.InternalPropBinding) ParameterModel(org.apache.tapestry5.model.ParameterModel) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) ComponentModel(org.apache.tapestry5.model.ComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator) Component(org.apache.tapestry5.runtime.Component) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 12 with ComponentPageElement

use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.

the class PageImplTest method detach_dirty_if_listener_throws_exception.

/**
 * Also checks that all listeners are invoked, even if one of them throws an exception.
 */
@Test
public void detach_dirty_if_listener_throws_exception() {
    ComponentPageElement element = mockComponentPageElement();
    Logger logger = mockLogger();
    PageLifecycleListener listener1 = newPageLifecycle();
    PageLifecycleListener listener2 = newPageLifecycle();
    RuntimeException t = new RuntimeException("Listener detach exception.");
    MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
    train_getLogger(element, logger);
    listener1.containingPageDidDetach();
    setThrowable(t);
    logger.error(contains("failed during page detach"), same(t));
    listener2.containingPageDidDetach();
    replay();
    Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
    page.setRootElement(element);
    page.addLifecycleListener(listener1);
    page.addLifecycleListener(listener2);
    assertTrue(page.detached());
    verify();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) Logger(org.slf4j.Logger) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 13 with ComponentPageElement

use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.

the class ComponentSourceImplTest method nested_element_within_page.

@Test
public void nested_element_within_page() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    ComponentPageElement element = mockComponentPageElement();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    train_get(cache, PAGE_NAME, page);
    train_getComponentElementByNestedId(page, NESTED_ELEMENT_ID, element);
    train_getComponent(element, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, null);
    assertSame(source.getComponent(PAGE_NAME + ":" + NESTED_ELEMENT_ID), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 14 with ComponentPageElement

use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.

the class AjaxComponentEventRequestHandler method handle.

public void handle(ComponentEventRequestParameters parameters) throws IOException {
    Page activePage = cache.get(parameters.getActivePageName());
    final Holder<Boolean> resultProcessorInvoked = Holder.create();
    resultProcessorInvoked.put(false);
    ComponentEventResultProcessor interceptor = new ComponentEventResultProcessor() {

        public void processResultValue(Object value) throws IOException {
            resultProcessorInvoked.put(true);
            resultProcessor.processResultValue(value);
        }
    };
    // If we end up doing a partial render, the page render queue service needs to know the
    // page that will be rendered (for logging purposes, if nothing else).
    queue.setRenderingPage(activePage);
    request.setAttribute(InternalConstants.PAGE_NAME_ATTRIBUTE_NAME, parameters.getActivePageName());
    if (pageActivator.activatePage(activePage.getRootElement().getComponentResources(), parameters.getPageActivationContext(), interceptor))
        return;
    Page containerPage = cache.get(parameters.getContainingPageName());
    ComponentPageElement element = containerPage.getComponentElementByNestedId(parameters.getNestedComponentId());
    // In many cases, the triggered element is a Form that needs to be able to
    // pass its event handler return values to the correct result processor.
    // This is certainly the case for forms.
    TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(interceptor);
    environment.push(ComponentEventResultProcessor.class, interceptor);
    environment.push(TrackableComponentEventCallback.class, callback);
    boolean handled = element.triggerContextEvent(parameters.getEventType(), parameters.getEventContext(), callback);
    if (!handled)
        throw new TapestryException(String.format("Request event '%s' (on component %s) was not handled; you must provide a matching event handler method in the component or in one of its containers.", parameters.getEventType(), element.getCompleteId()), element, null);
    environment.pop(TrackableComponentEventCallback.class);
    environment.pop(ComponentEventResultProcessor.class);
    // If the result processor was passed a value, then it will already have rendered. Otherwise it was not passed a value,
    // but it's still possible that we still want to do a partial page render ... if filters were added to the render queue.
    // In that event, run the partial page render now and return.
    boolean wasInvoked = resultProcessorInvoked.get();
    if ((!wasInvoked) && queue.isPartialRenderInitialized()) {
        partialRenderer.renderPartialPageMarkup();
        return;
    }
    if (wasInvoked) {
        return;
    }
    // Send an empty JSON reply if no value was returned from the component event handler method.
    // This is the typical behavior when an Ajax component event handler returns null. It still
    // will go through a pipeline that will add information related to partial page rendering.
    resultProcessor.processResultValue(new JSONObject());
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentEventResultProcessor(org.apache.tapestry5.services.ComponentEventResultProcessor) JSONObject(org.apache.tapestry5.json.JSONObject) TrackableComponentEventCallback(org.apache.tapestry5.TrackableComponentEventCallback) Page(org.apache.tapestry5.internal.structure.Page) JSONObject(org.apache.tapestry5.json.JSONObject) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 15 with ComponentPageElement

use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.

the class ComponentAssemblerImpl method addRootComponentMixins.

private void addRootComponentMixins(PageAssembly assembly, ComponentPageElement element) {
    for (String className : instantiator.getModel().getMixinClassNames()) {
        assembly.weight++;
        Instantiator mixinInstantiator = instantiatorSource.getInstantiator(className);
        ComponentModel model = instantiator.getModel();
        element.addMixin(InternalUtils.lastTerm(className), mixinInstantiator, model.getOrderForMixin(className));
    }
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator)

Aggregations

Test (org.testng.annotations.Test)13 ComponentModel (org.apache.tapestry5.model.ComponentModel)11 ComponentPageElement (org.apache.tapestry5.internal.structure.ComponentPageElement)10 Page (org.apache.tapestry5.internal.structure.Page)10 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)8 Instantiator (org.apache.tapestry5.internal.services.Instantiator)8 Component (org.apache.tapestry5.runtime.Component)8 Binding (org.apache.tapestry5.Binding)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)5 InternalPropBinding (org.apache.tapestry5.internal.bindings.InternalPropBinding)4 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)4 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)3 ComponentResources (org.apache.tapestry5.ComponentResources)3 MarkupWriter (org.apache.tapestry5.MarkupWriter)3 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)3 EmbeddedComponentModel (org.apache.tapestry5.model.EmbeddedComponentModel)3 ComponentEventResultProcessor (org.apache.tapestry5.services.ComponentEventResultProcessor)3 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)3 TrackableComponentEventCallback (org.apache.tapestry5.TrackableComponentEventCallback)2 Location (org.apache.tapestry5.commons.Location)2