Search in sources :

Example 21 with ComponentPageElement

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

the class AjaxComponentInstanceEventResultProcessorTest method render_component_within_page.

@Test
public void render_component_within_page() throws IOException {
    String nestedId = "foo.bar.baz";
    String pageName = "Biff";
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    ComponentResources resources = mockComponentResources();
    Component component = mockComponent();
    Component pageComponent = mockComponent();
    ComponentPageElement element = mockComponentPageElement();
    ComponentEventResultProcessor master = mockComponentEventResultProcessor();
    train_getComponentResources(component, resources);
    train_getPage(resources, pageComponent);
    train_getPageName(resources, pageName);
    train_get(cache, pageName, page);
    train_getNestedId(resources, nestedId);
    train_getComponentElementByNestedId(page, nestedId, element);
    master.processResultValue(element);
    replay();
    ComponentEventResultProcessor<Component> processor = new AjaxComponentInstanceEventResultProcessor(cache, master);
    processor.processResultValue(component);
    verify();
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentEventResultProcessor(org.apache.tapestry5.services.ComponentEventResultProcessor) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 22 with ComponentPageElement

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

the class BeanBlockSourceImplTest method train_getBlock.

protected final void train_getBlock(Page page, String blockId, Block block) {
    ComponentPageElement element = mockComponentPageElement();
    train_getRootElement(page, element);
    expect(element.getBlock(blockId)).andReturn(block);
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement)

Example 23 with ComponentPageElement

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

the class ComponentPageElementImpl method addEmbeddedElement.

void addEmbeddedElement(ComponentPageElement child) {
    if (children == null)
        children = CollectionFactory.newList();
    String childId = child.getId();
    for (ComponentPageElement existing : children) {
        if (existing.getId().equalsIgnoreCase(childId))
            throw new TapestryException(StructureMessages.duplicateChildComponent(this, childId), child, new TapestryException(StructureMessages.originalChildComponent(this, childId, existing.getLocation()), existing, null));
    }
    children.add(child);
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 24 with ComponentPageElement

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

the class ComponentPageElementImpl method processEventTriggering.

@SuppressWarnings("all")
private boolean processEventTriggering(String eventType, EventContext context, ComponentEventCallback callback) {
    boolean result = false;
    ComponentPageElement component = this;
    String componentId = "";
    // Provide a default handler for when the provided handler is null.
    final ComponentEventCallback providedHandler = callback == null ? new NotificationEventCallback(eventType, completeId) : callback;
    ComponentEventCallback wrapped = new ComponentEventCallback() {

        public boolean handleResult(Object result) {
            if (result instanceof Boolean)
                return (Boolean) result;
            return providedHandler.handleResult(result);
        }
    };
    RuntimeException rootException = null;
    // Because I don't like to reassign parameters.
    String currentEventType = eventType;
    EventContext currentContext = context;
    // Track the location of the original component for the event, even as we work our way up
    // the hierarchy. This may not be ideal if we trigger an "exception" event ... or maybe
    // it's right (it's the location of the originally thrown exception).
    Location location = component.getComponentResources().getLocation();
    while (component != null) {
        try {
            Logger logger = component.getEventLogger();
            ComponentEvent event = new ComponentEventImpl(currentEventType, componentId, currentContext, wrapped, elementResources, exactParameterCountMatch, coreResources.getComponentModel(), logger);
            logger.debug(TapestryMarkers.EVENT_DISPATCH, "Dispatch event: {}", event);
            result |= component.dispatchEvent(event);
            if (event.isAborted())
                return result;
        }// not the JVM).
         catch (Exception ex) {
            if (rootException != null)
                throw rootException;
            // We know component is not null and therefore has a component resources that
            // should have a location.
            // Wrap it up to help ensure that a location is available to the event handler
            // method or,
            // more likely, to the exception report page.
            rootException = new ComponentEventException(ex.getMessage(), eventType, context, location, ex);
            // Switch over to triggering an "exception" event, starting in the component that
            // threw the exception.
            currentEventType = "exception";
            currentContext = createParameterContext(rootException);
            continue;
        }
        // On each bubble up, make the event appear to come from the previous component
        // in which the event was triggered.
        componentId = component.getId();
        component = component.getContainerElement();
    }
    if (rootException != null)
        throw rootException;
    return result;
}
Also used : ComponentEventImpl(org.apache.tapestry5.internal.services.ComponentEventImpl) Logger(org.slf4j.Logger) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext) NotificationEventCallback(org.apache.tapestry5.internal.util.NotificationEventCallback) Location(org.apache.tapestry5.commons.Location)

Example 25 with ComponentPageElement

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

the class InternalComponentResourcesImplTest method render_informal_parameters_no_bindings.

@Test
public void render_informal_parameters_no_bindings() {
    ComponentPageElement element = mockComponentPageElement();
    Component component = mockComponent();
    Instantiator ins = mockInstantiator(component);
    MarkupWriter writer = mockMarkupWriter();
    TypeCoercer coercer = mockTypeCoercer();
    ComponentModel model = mockComponentModel();
    train_getModel(ins, model);
    replay();
    InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, elementResources, null, null, ins, false);
    resources.renderInformalParameters(writer);
    verify();
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) 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)

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