Search in sources :

Example 21 with Element

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

the class UploadTest method begin_render_writes_input_tag.

@Test
public void begin_render_writes_input_tag() throws Exception {
    MarkupWriter writer = createMarkupWriter();
    writer.element("form");
    FormSupport formSupport = mockFormSupport();
    ComponentResources resources = mockComponentResources();
    FieldValidator validator = mockFieldValidator();
    Request request = mockRequest();
    train_isXHR(request, false);
    formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
    validator.render(writer);
    resources.renderInformalParameters(writer);
    replay();
    Upload component = new Upload(null, null, null, null, resources, null);
    component.injectDecorator(new BaseValidationDecorator()).injectFormSupport(formSupport).injectFieldValidator(validator).injectRequest(request);
    component.beginRender(writer);
    Element element = writer.getElement();
    assertNotNull(element);
    assertEquals(element.getName(), "input");
    assertEquals(element.getAttribute("type"), "file");
    // assertEquals(element.getAttribute("name"),null);
    // assertEquals(element.getAttribute("id"),null);
    verify();
}
Also used : Element(org.apache.tapestry5.dom.Element) Request(org.apache.tapestry5.http.services.Request) FormSupport(org.apache.tapestry5.services.FormSupport) Test(org.testng.annotations.Test)

Example 22 with Element

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

the class DynamicTemplateSaxParser method element.

private DynamicTemplateElement element() {
    String elementURI = tokenStream.getNamespaceURI();
    String elementName = tokenStream.getLocalName();
    String blockId = null;
    int count = tokenStream.getAttributeCount();
    List<DynamicTemplateAttribute> attributes = CollectionFactory.newList();
    Location location = getLocation();
    for (int i = 0; i < count; i++) {
        QName qname = tokenStream.getAttributeName(i);
        // The name will be blank for an xmlns: attribute
        String localName = qname.getLocalPart();
        if (InternalUtils.isBlank(localName))
            continue;
        String uri = qname.getNamespaceURI();
        String value = tokenStream.getAttributeValue(i);
        if (localName.equals("id")) {
            Matcher matcher = PARAM_ID_PATTERN.matcher(value);
            if (matcher.matches()) {
                blockId = matcher.group(1);
                continue;
            }
        }
        Mapper<DynamicDelegate, String> attributeValueExtractor = createCompositeExtractorFromText(value, location);
        attributes.add(new DynamicTemplateAttribute(uri, localName, attributeValueExtractor));
    }
    if (blockId != null)
        return block(blockId);
    List<DynamicTemplateElement> body = CollectionFactory.newList();
    boolean atEnd = false;
    while (!atEnd) {
        switch(tokenStream.next()) {
            case START_ELEMENT:
                // Recurse into this new element
                body.add(element());
                break;
            case END_ELEMENT:
                body.add(END);
                atEnd = true;
                break;
            default:
                addTextContent(body);
        }
    }
    return createElementWriterElement(elementURI, elementName, attributes, body);
}
Also used : Matcher(java.util.regex.Matcher) QName(javax.xml.namespace.QName) DynamicDelegate(org.apache.tapestry5.services.dynamic.DynamicDelegate) Location(org.apache.tapestry5.commons.Location)

Example 23 with Element

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

the class PageLoaderImpl method parameter.

private void parameter(AssemblerContext context) {
    final ParameterToken token = context.next(ParameterToken.class);
    context.add(new PageAssemblyAction() {

        public void execute(PageAssembly pageAssembly) {
            String parameterName = token.name;
            ComponentPageElement element = pageAssembly.createdElement.peek();
            Location location = token.getLocation();
            BlockImpl block = new BlockImpl(location, interner.format("Parameter %s of %s", parameterName, element.getCompleteId()));
            Binding binding = new LiteralBinding(location, "block parameter " + parameterName, block);
            EmbeddedComponentAssembler embeddedAssembler = pageAssembly.embeddedAssembler.peek();
            ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
            if (binder == null) {
                throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", element.getCompleteId(), parameterName), location, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
            }
            binder.bind(pageAssembly.createdElement.peek(), binding);
            pageAssembly.bodyElement.push(block);
        }
    });
    consumeToEndElementAndPopBodyElement(context);
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding) LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues) Location(org.apache.tapestry5.commons.Location)

Example 24 with Element

use of org.apache.tapestry5.dom.Element 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)

Example 25 with Element

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

the class ComponentEventRequestHandlerImpl method handle.

public void handle(ComponentEventRequestParameters parameters) throws IOException {
    Page activePage = cache.get(parameters.getActivePageName());
    if (pageActivator.activatePage(activePage.getRootElement().getComponentResources(), parameters.getPageActivationContext(), resultProcessor)) {
        return;
    }
    Page containerPage = cache.get(parameters.getContainingPageName());
    TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(resultProcessor);
    environment.push(ComponentEventResultProcessor.class, resultProcessor);
    environment.push(TrackableComponentEventCallback.class, callback);
    ComponentPageElement element = containerPage.getComponentElementByNestedId(parameters.getNestedComponentId());
    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 (callback.isAborted()) {
        callback.rethrow();
        return;
    }
    if (!response.isCommitted()) {
        resultProcessor.processResultValue(activePage.getName());
    }
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) TrackableComponentEventCallback(org.apache.tapestry5.TrackableComponentEventCallback) Page(org.apache.tapestry5.internal.structure.Page) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Aggregations

Element (elemental2.dom.Element)269 HTMLElement (elemental2.dom.HTMLElement)215 Test (org.junit.Test)175 HTMLDivElement (elemental2.dom.HTMLDivElement)129 HTMLButtonElement (elemental2.dom.HTMLButtonElement)63 HTMLInputElement (elemental2.dom.HTMLInputElement)60 Element (org.apache.tapestry5.dom.Element)39 DOMTokenList (elemental2.dom.DOMTokenList)38 Test (org.testng.annotations.Test)34 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)32 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)29 MarkupWriter (org.apache.tapestry5.MarkupWriter)16 ArrayList (java.util.ArrayList)14 IsElement (org.jboss.gwt.elemento.core.IsElement)14 List (java.util.List)13 Elements (org.jboss.gwt.elemento.core.Elements)13 HTMLSelectElement (elemental2.dom.HTMLSelectElement)12 EventType.click (org.jboss.gwt.elemento.core.EventType.click)12 ComponentModel (org.apache.tapestry5.model.ComponentModel)11 Ids (org.jboss.hal.resources.Ids)11