Search in sources :

Example 16 with ComponentPageElement

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

the class PageLoaderImpl method connectInheritedParameter.

private void connectInheritedParameter(ComponentPageElement container, ComponentPageElement embedded, String parameterName, String containerParameterName) {
    // TODO: This assumes that the two parameters are both on the core component and not on
    // a mixin. I think this could be improved with more static analysis.
    Binding containerBinding = container.getBinding(containerParameterName);
    if (containerBinding == null)
        return;
    // This helps with debugging, and re-orients any thrown exceptions
    // to the location of the inherited binding, rather than the container component's
    // binding.
    // Binding inherited = new InheritedBinding(description, containerBinding, embedded.getLocation());
    embedded.bindParameter(parameterName, containerBinding);
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding)

Example 17 with ComponentPageElement

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

the class PageLoaderImpl method copyInformalParameters.

private void copyInformalParameters(ComponentPageElement container, ComponentPageElement embedded) {
    // TODO: Much more, this is an area where we can make things a bit more efficient by tracking
    // what has and hasn't been bound in the EmbeddedComponentAssembler (and identifying what is
    // and isn't informal).
    ComponentModel model = embedded.getComponentResources().getComponentModel();
    Map<String, Binding> informals = container.getInformalParameterBindings();
    for (String name : informals.keySet()) {
        if (model.getParameterModel(name) != null)
            continue;
        Binding binding = informals.get(name);
        embedded.bindParameter(name, binding);
    }
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding) ComponentModel(org.apache.tapestry5.model.ComponentModel) EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel)

Example 18 with ComponentPageElement

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

the class ComponentSourceImpl method getComponent.

public Component getComponent(String completeId) {
    assert InternalUtils.isNonBlank(completeId);
    int colonx = completeId.indexOf(':');
    if (colonx < 0) {
        Page page = pageCache.get(completeId);
        return page.getRootComponent();
    }
    String pageName = completeId.substring(0, colonx);
    Page page = pageCache.get(pageName);
    String nestedId = completeId.substring(colonx + 1);
    String mixinId = null;
    int dollarx = nestedId.indexOf("$");
    if (dollarx > 0) {
        mixinId = nestedId.substring(dollarx + 1);
        nestedId = nestedId.substring(0, dollarx);
    }
    ComponentPageElement element = page.getComponentElementByNestedId(nestedId);
    if (mixinId == null)
        return element.getComponent();
    ComponentResources resources = element.getMixinResources(mixinId);
    return resources.getComponent();
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) Page(org.apache.tapestry5.internal.structure.Page) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 19 with ComponentPageElement

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

the class PageActivationContextCollectorImpl method collectPageActivationContext.

public Object[] collectPageActivationContext(String pageName) {
    Boolean hasHandler = cache.get(pageName);
    if (hasHandler == null) {
        ComponentModel model = modelSource.getPageModel(pageName);
        hasHandler = model.handlesEvent(EventConstants.PASSIVATE);
        cache.put(pageName, hasHandler);
    }
    if (!hasHandler)
        return EMPTY;
    // Get or create a page instance and trigger the event.
    Page page = requestPageCache.get(pageName);
    ComponentPageElement element = page.getRootElement();
    final Holder<Object[]> holder = Holder.create();
    ComponentEventCallback callback = new ComponentEventCallback() {

        public boolean handleResult(Object result) {
            holder.put(typeCoercer.coerce(result, Object[].class));
            return true;
        }
    };
    element.triggerEvent(EventConstants.PASSIVATE, null, callback);
    if (!holder.hasValue())
        return EMPTY;
    return holder.get();
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentModel(org.apache.tapestry5.model.ComponentModel) Page(org.apache.tapestry5.internal.structure.Page) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback)

Example 20 with ComponentPageElement

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

the class PageActivationContextCollectorImplTest method tryWithContext.

private void tryWithContext(String pageName, final Object context, Object... expected) {
    ComponentModelSource modelSource = mockComponentModelSource();
    RequestPageCache pageCache = mockRequestPageCache();
    ComponentPageElement element = mockComponentPageElement();
    ComponentModel model = mockComponentModel();
    Page page = mockPage();
    expect(modelSource.getPageModel(pageName)).andReturn(model);
    expect(model.handlesEvent(EventConstants.PASSIVATE)).andReturn(true);
    train_get(pageCache, pageName, page);
    train_getRootElement(page, element);
    IAnswer answer = new IAnswer() {

        public Object answer() throws Throwable {
            Object[] args = EasyMock.getCurrentArguments();
            ComponentEventCallback callback = (ComponentEventCallback) args[2];
            return callback.handleResult(context);
        }
    };
    expect(element.triggerEvent(EasyMock.eq(EventConstants.PASSIVATE), (Object[]) EasyMock.isNull(), EasyMock.isA(ComponentEventCallback.class))).andAnswer(answer);
    replay();
    PageActivationContextCollector collector = new PageActivationContextCollectorImpl(coercer, pageCache, modelSource);
    Object[] actual = collector.collectPageActivationContext(pageName);
    assertArraysEqual(actual, expected);
}
Also used : IAnswer(org.easymock.IAnswer) ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentModel(org.apache.tapestry5.model.ComponentModel) Page(org.apache.tapestry5.internal.structure.Page) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback)

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