Component Bindings
Components are configured by binding their parameters. Binding of parameters may occur inside a page or component template, or a page or component specification.
When binding a component parameter, the value to be bound may be just a literal string, or it could be an OGNL expression, or subject to any of a number of other interpretations. Tapestry uses a prefix value, such as "ognl:", or "message:", to identify how the rest of the value is to be interprted. The prefix identifies the binding type:
Binding Type | Description | Example | OGNL Equivalent |
---|---|---|---|
asset | References an asset of the component. | asset:stylesheet | ognl:assets.stylesheet |
bean | References a named bean (defined by a <bean> element). | bean:validationDelegate | ognl:beans.validationDelegate |
component | References a nested component with the provided component id. | component:form | ognl:components.form |
hivemind | References a HiveMind object, much like <inject>. | hivemind:service:app.MyService | |
listener | The name of a listener method. | listener:formSubmit | ognl:listeners.formSubmit |
literal | Used to "escape" a binding prefix, marking the suffix as a literal value. | literal:ognl:not-an-expression | |
message | References a localized message from the component's message catalog. | message:page-title | ognl:messages.getMessage("page-title") |
ognl | An OGNL expression to be evaluated. | ognl:engine.visit.admin | |
state | True of false dependening on whether the named application state object exists. | state:visit | |
translator | Initializer used to obtain and configure a Translator instance. | translator:number,pattern=# | |
validator | Initializer used to obtain and configure an IValidator instance (used with ValidField). | validator:string,required,minimumLength=5 | |
validators | List of configured Validator instances (used with TextField and others). | validators:email,required,minLength=10 |
Most of these are quite straight forward; the validator, validators and translator prefixes require some additional description.
Many of the bindings are driven by a HiveMind configuration; the configuration will define the available values, and contributing the configuration allows new values to be defined.
Binding Prefix | Configuration |
---|---|
translator | tapestry.form.translator.Translators |
state | tapestry.state.ApplicationObjects |
validator | tapestry.valid.Validators |
Binding Type Defaults
Tapestry 4.0 introduces a new idea: default binding types. Each component parameter may define a default binding type (using the default-binding attribute of the <parameter> element).
If a binding reference does not have a prefix, the default binding type is used.
Because of this, the following two snippets are identical:
<ul element="ul" jwcid="@Foreach" source="ognl:items" value="ognl:item"> <li><span jwcid="@Insert" value="ognl:item.name"/> </ul>
<ul element="ul" jwcid="@Foreach" source="items" value="item"> <li><span jwcid="@Insert" value="item.name"/> </ul>
This works because the Insert component defines the default-binding for the value parameter to be "ognl". Likewise, the source and value parameters of the Foreach component are defined to be "ognl". However, the element parameter of the Foreach component has a binding type of "literal".
This is a decision made by the component author. If a particular parameter is (nearly) always bound using a particular binding type, then a default-binding may be set. The default binding can always be overriden with an explicit binding type prefix.
What about parameters that don't define a default binding type? The answer to this question (which includes all informal parameters), is that it depends on whether the parameter is bound in an HTML template, or in a page or component specification. In an HTML template, the default binding type is "literal". In a specification, the default binding type is "ognl".