Chapter 4. Tapestry Components

Table of Contents

Parameters and Bindings
Formal vs. Informal Parameters
Embedded Components
HTML Templates
Tapestry and HTML Production
Implicitly removed bodies
Explicitly removed bodies
Limiting template content
Limits
Localization
Assets
Helper Beans
Component Specification
<specification> element
<description> element
<parameter> element
<reserved-parameter> element
<property> element
<bean> element
<set-property> element
<static-value> element
<property-value> element
<component> element
Binding elements
Asset elements

Tapestry components are "black boxes" that are involved with both rendering HTML responses and responding to HTTP requests.

A Tapestry component is defined by its specification. The specification is an XML file that defines the type of the component, it parameters, the template used by the component, any components embedded within it and how they are 'wired up', and (less often) any assets used by the component.

At runtime, the specification is used to identify and instantiate a class for the component. When the page containing the component is rendered, the component will access its HTML template to find the static HTML and embedded components it will render.

Parameters and Bindings

Tapestry components are designed to work with each other, within the context of a page and application. The process of rendering a page is largely about pulling information from a source into a component and doing something with it.

For example, on a welcome page, a component might get the userName property from the visit object and insert it into the HTML response.

Each component has a specific set of parameters. Parameters have a name, a type and may be required or optional.

To developers experienced with Java GUIs, it may appear that Tapestry component parameters are the same as JavaBeans properties. This is not completes true. JavaBeans properties are set-and-forget; the designer sets a value for the property using a visual editor and the value is saved with the bean until it is used at runtime.

Parameters define the type of value needed, but not the actual value. This value is provided by a special object called a binding. The binding is responsible for providing the value for the parameter as it is needed.

A binding is a source and sink of data. A component uses a binding to import or export a data value.

There are two types of bindings: static and dynamic. Static bindings are read-only; the value for the binding is specified in the component specification.

Dynamic bindings are more prevalent and useful. A dynamic binding uses a JavaBeans property name to retrieve the value when needed by the component. The source of this data is a property of some component.

In fact, dynamic bindings use property paths, allowing a binding to 'crawl' deeply through an object graph to access the value it needs. This frees the components from relying totally on the properties of their container, instead they are free to access properties of more distant objects.