Search in sources :

Example 11 with Page

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

the class BeanBlockSourceImplTest method found_display_block.

@Test
public void found_display_block() {
    Block block = mockBlock();
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    BeanBlockContribution contribution = new DisplayBlockContribution("mydata", "MyPage", "mydisplay");
    Collection<BeanBlockContribution> configuration = newList(contribution);
    train_get(cache, "MyPage", page);
    train_getBlock(page, "mydisplay", block);
    replay();
    BeanBlockSource source = new BeanBlockSourceImpl(cache, createBeanBlockOverrideSource(cache), configuration);
    // Check case insensitivity while we are at it.
    assertTrue(source.hasDisplayBlock("MyData"));
    Block actual = source.getDisplayBlock("MyData");
    assertSame(actual, block);
    verify();
}
Also used : DisplayBlockContribution(org.apache.tapestry5.services.DisplayBlockContribution) BeanBlockSource(org.apache.tapestry5.services.BeanBlockSource) Block(org.apache.tapestry5.Block) Page(org.apache.tapestry5.internal.structure.Page) BeanBlockContribution(org.apache.tapestry5.services.BeanBlockContribution) Test(org.testng.annotations.Test)

Example 12 with Page

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

the class AjaxComponentInstanceEventResultProcessor method processResultValue.

public void processResultValue(Component value) throws IOException {
    ComponentResources resources = value.getComponentResources();
    boolean isPage = value == resources.getPage();
    String pageName = resources.getPageName();
    if (isPage) {
        // This will ultimately send a JSON response to redirect to the page
        masterProcessor.processResultValue(pageName);
        return;
    }
    // Otherwise, a component within a page. Components are transformed to implement RenderCommand, but if we just
    // pass the component itself to the master processor, we'll get in a loop, so we instead
    // pass the ComponentPageElement (which implements RenderCommand as well).
    Page page = cache.get(pageName);
    String nestedId = resources.getNestedId();
    RenderCommand command = page.getComponentElementByNestedId(nestedId);
    masterProcessor.processResultValue(command);
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) Page(org.apache.tapestry5.internal.structure.Page) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 13 with Page

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

the class PageLoaderImpl method addParameterBindingAction.

private void addParameterBindingAction(AssemblerContext context, final EmbeddedComponentAssembler embeddedAssembler, final String parameterName, final String parameterValue, final String metaDefaultBindingPrefix, final Location location, final boolean ignoreUnmatchedFormal) {
    if (embeddedAssembler.isBound(parameterName))
        return;
    embeddedAssembler.setBound(parameterName);
    if (parameterValue.startsWith(InternalConstants.INHERIT_BINDING_PREFIX)) {
        String containerParameterName = parameterValue.substring(InternalConstants.INHERIT_BINDING_PREFIX.length());
        addInheritedBindingAction(context, parameterName, containerParameterName);
        return;
    }
    context.add(new PageAssemblyAction() {

        public void execute(PageAssembly pageAssembly) {
            // Because of published parameters, we have to wait until page assembly time to throw out
            // informal parameters bound to components that don't support informal parameters ...
            // otherwise we'd throw out (sometimes!) published parameters.
            final ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
            if (binder == null) {
                if (ignoreUnmatchedFormal) {
                    return;
                }
                throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", pageAssembly.createdElement.peek().getCompleteId(), parameterName), null, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
            }
            final String defaultBindingPrefix = binder.getDefaultBindingPrefix(metaDefaultBindingPrefix);
            InternalComponentResources containerResources = pageAssembly.activeElement.peek().getComponentResources();
            ComponentPageElement embeddedElement = pageAssembly.createdElement.peek();
            InternalComponentResources embeddedResources = embeddedElement.getComponentResources();
            Binding binding = elementFactory.newBinding(parameterName, containerResources, embeddedResources, defaultBindingPrefix, parameterValue, location);
            binder.bind(embeddedElement, binding);
        }
    });
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Example 14 with Page

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

the class PageLoaderImpl method startComponent.

private EmbeddedComponentAssembler startComponent(AssemblerContext context) {
    StartComponentToken token = context.next(StartComponentToken.class);
    ComponentAssembler assembler = context.assembler;
    String elementName = token.getElementName();
    // Initial guess: the type from the token (but this may be null in many cases).
    String embeddedType = token.getComponentType();
    // This may be null for an anonymous component.
    String embeddedId = token.getId();
    String embeddedComponentClassName = null;
    final EmbeddedComponentModel embeddedModel = embeddedId == null ? null : assembler.getModel().getEmbeddedComponentModel(embeddedId);
    if (embeddedId == null)
        embeddedId = assembler.generateEmbeddedId(embeddedType);
    if (embeddedModel != null) {
        String modelType = embeddedModel.getComponentType();
        if (InternalUtils.isNonBlank(modelType) && embeddedType != null) {
            throw new TapestryException(String.format("Embedded component '%s' provides a type attribute in the template ('%s') " + "as well as in the component class ('%s'). You should not provide a type attribute " + "in the template when defining an embedded component within the component class.", embeddedId, embeddedType, modelType), token, null);
        }
        embeddedType = modelType;
        embeddedComponentClassName = embeddedModel.getComponentClassName();
    }
    String componentClassName = embeddedComponentClassName;
    if (InternalUtils.isNonBlank(embeddedType)) {
        try {
            componentClassName = componentClassResolver.resolveComponentTypeToClassName(embeddedType);
        } catch (RuntimeException ex) {
            throw new TapestryException(ex.getMessage(), token, ex);
        }
    }
    // OK, now we can record an action to get it instantiated.
    EmbeddedComponentAssembler embeddedAssembler = assembler.createEmbeddedAssembler(embeddedId, componentClassName, embeddedModel, token.getMixins(), token.getLocation());
    addActionForEmbeddedComponent(context, embeddedAssembler, embeddedId, elementName, componentClassName);
    addParameterBindingActions(context, embeddedAssembler, embeddedModel);
    if (embeddedModel != null && embeddedModel.getInheritInformalParameters()) {
        // Another two-step: The first "captures" the container and embedded component. The second
        // occurs at the end of the page setup.
        assembler.add(new PageAssemblyAction() {

            public void execute(PageAssembly pageAssembly) {
                final ComponentPageElement container = pageAssembly.activeElement.peek();
                final ComponentPageElement embedded = pageAssembly.createdElement.peek();
                pageAssembly.deferred.add(new PageAssemblyAction() {

                    public void execute(PageAssembly pageAssembly) {
                        copyInformalParameters(container, embedded);
                    }
                });
            }
        });
    }
    return embeddedAssembler;
}
Also used : EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 15 with Page

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

the class PageActivationContextCollectorImplTest method page_with_no_context.

@Test
public void page_with_no_context() {
    String pageName = "mypage";
    ComponentModel model = mockComponentModel();
    ComponentModelSource modelSource = mockComponentModelSource();
    RequestPageCache pageCache = mockRequestPageCache();
    Page page = mockPage();
    ComponentPageElement element = mockComponentPageElement();
    expect(modelSource.getPageModel(pageName)).andReturn(model);
    expect(model.handlesEvent(EventConstants.PASSIVATE)).andReturn(true);
    train_get(pageCache, pageName, page);
    train_getRootElement(page, element);
    expect(element.triggerEvent(EasyMock.eq(EventConstants.PASSIVATE), (Object[]) EasyMock.isNull(), EasyMock.isA(ComponentEventCallback.class))).andReturn(false);
    replay();
    PageActivationContextCollector collector = new PageActivationContextCollectorImpl(coercer, pageCache, modelSource);
    Object[] actual = collector.collectPageActivationContext(pageName);
    assertEquals(actual.length, 0);
}
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) Test(org.testng.annotations.Test)

Aggregations

Page (org.apache.tapestry5.internal.structure.Page)33 Test (org.testng.annotations.Test)29 Component (org.apache.tapestry5.runtime.Component)17 Link (org.apache.tapestry5.http.Link)13 ComponentResources (org.apache.tapestry5.ComponentResources)10 ComponentPageElement (org.apache.tapestry5.internal.structure.ComponentPageElement)10 ComponentModel (org.apache.tapestry5.model.ComponentModel)10 Document (org.apache.tapestry5.dom.Document)7 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)6 JSONObject (org.apache.tapestry5.json.JSONObject)6 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)6 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)5 ContentType (org.apache.tapestry5.http.ContentType)5 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)5 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)5 URL (java.net.URL)4 Binding (org.apache.tapestry5.Binding)4 MarkupWriter (org.apache.tapestry5.MarkupWriter)4