This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Component Templates

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: scrollbar
{|background=#eee} {contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=@self|labels=component-templates,components,rendering,response} {float}
Wiki Markup
; margin: 1em
titleRelated Articles
Content by Label
titleRelated Articles
cqllabel in ("component-templates","components","rendering","response") and space = currentSpace()

Under Tapestry, a component template is a file that contains the markup for a component.

Component templates are well formed XML documents. That means that every open tag must have a matching close tag, every attribute must be quoted, and so forth.


Note: At runtime, Tapestry parses the documents and only checks for wellformedness. Even when the document has a DTD or schema, there are no validity checks.

For the most part, these templates are standard HTML/XHTML; Tapestry extensions to ordinary markup are provided in the form of a Tapestry XML namespace (xmlns):

Code Block
titleA template for a page
<html t:type="layout" xmlns:t="">
    <h1>Bonjour from HelloWorld component.</h1>

We'll cover the specific content of templates shortly, but first a few details about connecting a component to its template.



It is necessary to enable support for a locale

before Tapestry will attempt to localize to that locale. This requires configuration in your application module (usually; if you are using the Tapestry Quickstart archetype, only locale "en" will be enabled by default.


The first one is for HTML5 and is recommended for Tapestry 5.2.5 and later. In versions prior to Tapestry 5.2.5, Tapestry didn't support the HTML5 doctype directly (but see the comments at TAP5-1040), but there's a partial for a work-around: just add the following to your page class (or your layout class, if you use one) instead of adding the doctype to your template (.tml) files:

Code Block
* Output the HTML5 doctype, as a work-around to
final void renderDocType(final MarkupWriter writer) {
    writer.getDocument().raw("<!DOCTYPE html>");
Tapestry 5.3 introduces introduced two significant improvements to template Doctypes. A template without a is parsed as if it had the HTML Doctype ({{}}). In fact, Tapestry creates an in-memory copy of the template that includes the doctype. A template with the HTML Doctype ({{}}) is parsed _as if_ it had the XHTML transitional Doctype. In fact, Tapestry creates an in-memory copy of the template that replaces the line. This applies as well to a template without any Doctype, in which case the XHTML transitional Doctype is inserted at the top. In either case, this means you can use arbitrary HTML entities, such as {{&copy;}} or {{&nbsp;}} without seeing the XML parsing errors that would occur in earlier releases.


Code Block
<html xmlns:t="">
        <title>Hello World Page</title>
        <h1>Hello World</h1>


For backwards compatibility, you may continue to use the old namespace URIs: or However or


 However, the following elements added, as part of Tapestry 5.1, will not work with the 5_0_0.xsd:


The 5_3.xsd fixes some minor bugs in the 5_1_0.xsd, but is functionally equivalent; 5_3.xsd and 5_4.xsd are identical.

Tapestry Elements

Tapestry elements are elements defined using the Tapestry namespace prefix (usually "t:").


A block may be anonymous, or it may have an id (specified with the id attribute). Only blocks with an id may be injected into the component.


A <t:block> must be in the Tapestry namespace, but the id attribute should not be. This is different from components in the template, where the t:id attribute that defines the component id must be in the Tapestry namespace.


Support for the <t:content> element was adding in Tapestry release 5.1. You must use the or ...5_3 or ...5_1_0.xsd) namespace URI for content to be recognized (otherwise you will see an error about a missing "content" component).


Support for the <t:remove> element was added in Tapestry release 5.1. You must use the or ...5_3 or ...5_1_0.xsd) namespace URI for remove to be recognized (otherwise you will see an error about a missing "remove" component).


Note that expansions escape any HTML reserved characters. Specifically, any less-than (<), greater than (>) and ampersand (&) are replaced with &lt;, &ampgtgt; and &amp; respectively. That is usually what you want. However, if your property contains HTML that you want rendered as raw markup, you can use the OutputRaw component instead, like this: <t:OutputRaw value="someContent"/> where someContent is a property containing HTML markup.


  • via the t:type attribute in the containing template, as in the above example, or
  • within the containing component's Java class using the @Component annotation (and using the t:id attribute on the element in the template). The Component annotation is attached to a field; the type of the component is determined by either the type of the field or the type attribute of the Component annotation.


This approach has certain efficiency advantages on both the server (less processing to render the page) and on the client (fewer characters to parse). Tools such as FireBug Firefox Developer Tools and Chrome Developer Tools are useful for allowing you to view the rendered HTML on the client properly.


Code Block
<t:extend xmlns:t="">
  <t:replace id="title">
    <h1><img src="${context:images/icon.jpg}"/>
    Customer Service</h1>