Search in sources :

Example 1 with Id

use of org.apache.tapestry5.annotations.Id in project flowlogix by flowlogix.

the class PeriodicUpdater method afterRender.

@AfterRender
void afterRender() {
    final String id = zone.getClientId();
    Link link;
    if (context == null) {
        link = resources.createEventLink(event);
    } else {
        link = resources.createEventLink(event, context);
    }
    final JSONObject spec = new JSONObject();
    spec.put("period", period);
    spec.put("elementId", id);
    spec.put("uri", link.toAbsoluteURI());
    jsSupport.addInitializerCall("periodicUpdater", spec);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) Link(org.apache.tapestry5.Link) AfterRender(org.apache.tapestry5.annotations.AfterRender)

Example 2 with Id

use of org.apache.tapestry5.annotations.Id in project tapestry-5 by apache.

the class SaxTemplateParser method element.

/**
 * Processes an element through to its matching end tag.
 *
 * An element can be:
 *
 * a Tapestry component via <t:type>
 *
 * a Tapestry component via t:type="type" and/or t:id="id"
 *
 * a Tapestry component via a library namespace
 *
 * A parameter element via <t:parameter>
 *
 * A parameter element via <p:name>
 *
 * A <t:remove> element (in the 5.1 schema)
 *
 * A <t:content> element (in the 5.1 schema)
 *
 * A <t:block> element
 *
 * The body <t:body>
 *
 * An ordinary element
 */
void element(TemplateParserState initialState) {
    TemplateParserState state = setupForElement(initialState);
    String uri = tokenStream.getNamespaceURI();
    String name = tokenStream.getLocalName();
    Version version = NAMESPACE_URI_TO_VERSION.get(uri);
    if (T_5_1.sameOrEarlier(version)) {
        if (name.equalsIgnoreCase("remove")) {
            removeContent();
            return;
        }
        if (name.equalsIgnoreCase("content")) {
            limitContent(state);
            return;
        }
        if (name.equalsIgnoreCase("extension-point")) {
            extensionPoint(state);
            return;
        }
        if (name.equalsIgnoreCase("replace")) {
            throw new RuntimeException("The <replace> element may only appear directly within an extend element.");
        }
        if (MUST_BE_ROOT.contains(name))
            mustBeRoot(name);
    }
    if (version != null) {
        if (name.equalsIgnoreCase("body")) {
            body();
            return;
        }
        if (name.equalsIgnoreCase("container")) {
            mustBeRoot(name);
        }
        if (name.equalsIgnoreCase("block")) {
            block(state);
            return;
        }
        if (name.equalsIgnoreCase("parameter")) {
            if (T_5_3.sameOrEarlier(version)) {
                throw new RuntimeException(String.format("The <parameter> element has been deprecated in Tapestry 5.3 in favour of '%s' namespace.", TAPESTRY_PARAMETERS_URI));
            }
            classicParameter(state);
            return;
        }
        possibleTapestryComponent(state, null, tokenStream.getLocalName().replace('.', '/'));
        return;
    }
    if (uri != null && uri.startsWith(LIB_NAMESPACE_URI_PREFIX)) {
        libraryNamespaceComponent(state);
        return;
    }
    if (TAPESTRY_PARAMETERS_URI.equals(uri)) {
        parameterElement(state);
        return;
    }
    // Just an ordinary element ... unless it has t:id or t:type
    possibleTapestryComponent(state, tokenStream.getLocalName(), null);
}
Also used : Version(org.apache.tapestry5.internal.services.SaxTemplateParser.Version)

Example 3 with Id

use of org.apache.tapestry5.annotations.Id in project tapestry-5 by apache.

the class SaxTemplateParser method possibleTapestryComponent.

/**
 * @param elementName
 * @param identifiedType
 *         the type of the element, usually null, but may be the
 *         component type derived from element
 */
private void possibleTapestryComponent(TemplateParserState state, String elementName, String identifiedType) {
    String id = null;
    String type = identifiedType;
    String mixins = null;
    int count = tokenStream.getAttributeCount();
    Location location = getLocation();
    List<TemplateToken> attributeTokens = CollectionFactory.newList();
    for (int i = 0; i < count; i++) {
        QName qname = tokenStream.getAttributeName(i);
        if (isXMLSpaceAttribute(qname))
            continue;
        // 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);
        Version version = NAMESPACE_URI_TO_VERSION.get(uri);
        if (version != null) {
            if (T_5_4.sameOrEarlier(version)) {
                strictMixinParameters = true;
            }
            if (localName.equalsIgnoreCase(ID_ATTRIBUTE_NAME)) {
                id = nullForBlank(value);
                validateId(id, "Component id '%s' is not valid; component ids must be valid Java identifiers: start with a letter, and consist of letters, numbers and underscores.");
                continue;
            }
            if (type == null && localName.equalsIgnoreCase(TYPE_ATTRIBUTE_NAME)) {
                type = nullForBlank(value);
                continue;
            }
            if (localName.equalsIgnoreCase(MIXINS_ATTRIBUTE_NAME)) {
                mixins = nullForBlank(value);
                continue;
            }
        // Anything else is the name of a Tapestry component parameter
        // that is simply
        // not part of the template's doctype for the element being
        // instrumented.
        }
        attributeTokens.add(new AttributeToken(uri, localName, value, location));
    }
    boolean isComponent = (id != null || type != null);
    if (mixins != null && !isComponent)
        throw new TapestryException(String.format("You may not specify mixins for element <%s> because it does not represent a component (which requires either an id attribute or a type attribute).", elementName), location, null);
    if (isComponent) {
        tokenAccumulator.add(new StartComponentToken(elementName, id, type, mixins, location));
    } else {
        tokenAccumulator.add(new StartElementToken(tokenStream.getNamespaceURI(), elementName, location));
    }
    addDefineNamespaceTokens();
    tokenAccumulator.addAll(attributeTokens);
    if (id != null)
        componentIds.put(id, location);
    processBody(state.insideComponent(isComponent));
}
Also used : Version(org.apache.tapestry5.internal.services.SaxTemplateParser.Version) QName(javax.xml.namespace.QName) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) Location(org.apache.tapestry5.commons.Location)

Example 4 with Id

use of org.apache.tapestry5.annotations.Id in project tapestry-5 by apache.

the class ComponentDefaultProviderImplTest method no_matching_property_for_default.

@Test
public void no_matching_property_for_default() {
    String parameterName = "myparam";
    String id = "mycomponentid";
    ComponentResources resources = mockComponentResources();
    Component container = mockComponent();
    PropertyAccess access = mockPropertyAccess();
    ClassPropertyAdapter classPropertyAdapter = mockClassPropertyAdapter();
    BindingSource bindingSource = mockBindingSource();
    train_getId(resources, id);
    train_getContainer(resources, container);
    train_getAdapter(access, container, classPropertyAdapter);
    train_getPropertyAdapter(classPropertyAdapter, id, null);
    replay();
    ComponentDefaultProvider source = new ComponentDefaultProviderImpl(access, bindingSource, null, null, null);
    assertNull(source.defaultBinding(parameterName, resources));
    verify();
}
Also used : BindingSource(org.apache.tapestry5.services.BindingSource) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) PropertyAccess(org.apache.tapestry5.commons.services.PropertyAccess) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 5 with Id

use of org.apache.tapestry5.annotations.Id in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method unknown_property_id.

@Test
public void unknown_property_id() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    model.addEmpty("shrub.foo()");
    try {
        model.getById("frobozz");
        unreachable();
    } catch (UnknownValueException ex) {
        assertEquals(ex.getMessage(), "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean does not contain a property with id \'frobozz\'.");
        assertListsEquals(ex.getAvailableValues().getValues(), "age", "firstName", "lastName", "shrubfoo");
    }
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)14 Element (org.apache.tapestry5.dom.Element)11 ComponentResources (org.apache.tapestry5.ComponentResources)5 Location (org.apache.tapestry5.commons.Location)5 Component (org.apache.tapestry5.runtime.Component)5 Logger (org.slf4j.Logger)5 HibernateEntityValueEncoder (org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder)4 Link (org.apache.tapestry5.http.Link)4 HeartbeatDeferred (org.apache.tapestry5.annotations.HeartbeatDeferred)3 Messages (org.apache.tapestry5.commons.Messages)3 Resource (org.apache.tapestry5.commons.Resource)3 ComponentActionSink (org.apache.tapestry5.corelib.internal.ComponentActionSink)3 Instantiator (org.apache.tapestry5.internal.services.Instantiator)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)3 Session (org.hibernate.Session)3 QName (javax.xml.namespace.QName)2 ClientElement (org.apache.tapestry5.ClientElement)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2