Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Component parameters are the primary means for a component instance and its container to communicate with each other. Parameters are used to configure component instances.

Div
stylefloat:right; margin: 1em
titleRelated Articles
classaui-label
Content by Label
showLabelsfalse
showSpacefalse
titleRelated Articles
cqllabel in ("expressions","component-classes","component-templates","parameters") and space = currentSpace()

...

Code Block
languagexml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_34.xsd">
    <t:pagelink page="Index">Go Home</t:pagelink>
</html>

...

The component above can be referenced in another component or page template, and its parameters bound:

Code Block
languagexml
<html t:type="layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_34.xsd">
    <p> Merry Christmas: <t:count end="3"> Ho! </t:count>
    </p>
</html>

The end attribute is used to bind the end parameter of the Count component. Here, it is being bound to the string value "3", which is automatically coerced by Tapestry into the int value, 3.

...

Prefix

Description

asset:

The relative path to an asset file (which must exist)

block:

The id of a block within the template

component:

The id of another component within the same template

context:

Context asset: path from context root

literal:

A literal string

nullfieldstrategy:

Used to locate a pre-defined NullFieldStrategy

message:

Retrieves a string from the component's message catalog

prop:

A property expression to read or update

symbol:

Used to read one of your symbols

translate:

The name of a configured translator

validate:

A validator specification used to create some number of field validators

var:

Allows a render variable of the component to be read or updated

...

Render variable names are case insensitive.

Property: Bindings

Main Article: Property Expressions

The "prop:" binding prefix indicates a property expression binding.

Property expressions are used to link a parameter of a component to a property of its container. Property expressions can navigate a series of properties and/or invoke methods, as well as several other useful patterns. See Component Parameters.

The default binding prefix in most cases is "prop:", which is why it is usually omitted.

Validate: Bindings

Main Article: Component Parameters Forms and Validation

The "validate:" binding prefix is highly specialized. It allows a short string to be used to create and configure the objects that perform input validation for form control components, such as TextField and Checkbox.

...

The list of available translators is configured by the TranslatorSource service.

Asset: Bindings

Main Article: Assets

Assets bindings are used to specify Component Parameters, static content served by Tapestry. By default, assets are located relative to the component class in your packaged application or module. This can be overridden by prefixing the path with "context:", in which case, the path is a context path from the root of the web application context. Because accessing context assets is relatively common, a separate "context:" binding prefix for that purpose exists (described below).

Context: Bindings

Main Article: Assets

Context bindings are like asset bindings, but the path is always relative to the root of the web application context. This is intended for use inside templates, i.e.:

...

Tip

Sometimes a parameter is marked as required, but may still be omitted if the underlying value is provided by some other means. This is the case, for example, with the Select component's value parameter, which may have its underlying value set by contributing a ValueEncoderSource. Be sure to read the component's parameter documentation carefully. Required simply enables checks that the parameter is bound, it does not mean that you must supply the binding in the template (or @Component annotation).

...

Don't use the ${...} syntax!

Main Article: Expansions

You generally should not use the Template Expansion syntax, ${...}, within component parameter bindings. Doing so results in the property inside the braces being converted to an (immutable) string, and will therefore result in a runtime exception if your component needs to update the value (whenever the default or explicit binding prefix is prop: or var:, since such component parameters are two-way bindings).

...

Informal Parameters

Main Article: Component Supporting Informal Parameters

Many components support informal parameters, additional parameters beyond the formally defined parameters. Informal parameters will be rendered into the output as additional attributes on the tag rendered by the component. Generally speaking, components that have a 1:1 relationship with a particular HTML tag (such as <TextField> and <input> will support informal parameters.

...

If your component should render informal parameters, just inject the ComponentResources for your component and invoke the renderInformalParameters() method. See Component See Supporting Informal Parameters for an example of how to do this.

...

Code Block
languagexml
<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_34.xsd">
    <p> Countdown:
        <t:count start="5" end="1" result="index">
          ${index} ...
        </t:count>
    </p>
</t:layout>

...

Code Block
languagexml
titleIndex.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_34.xsd">
  <body>
    <div t:type="layout" t:menuTitle="literal:The Title">
      ...
    </div>
  </body>
</html>
Code Block
languagexml
titleLayout.tml
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_34.xsd">

	<div t:type="title" t:title="inherit:menuTitle"></div>

	<t:body />

</t:container>

...

Parameter Type Coercion

Main Article: Component Parameters Parameter Type Coercion

Tapestry includes a mechanism for coercing types automatically. Most often, this is used to convert literal strings into appropriate values, but in many cases, more complex conversions will occur. This mechanism is used for component parameters, such as when an outer component passes a literal string to an inner component that is expecting an integer.

You can easily contribute new coercions for your own purposes.

Parameter Names

...

In rare cases, you may want to take different behaviors based on whether a parameter is bound or not. This can be accomplished by querying the component's resources, which can be injected into the component using the @Inject annotation:

Code Block
languagejava
public class MyComponent
{
  @Parameter
  private int myParam;

  @Inject
  private ComponentResources resourcescomponentResources;

  @BeginRender
  void setup()
  {
      if (resourcescomponentResources.isBound("myParam"))
      {
        . . .
      }
  }
}

...

Code Block
languagexml
titleContainerComponent.tml
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_34.xsd">
<t:pageLink t:id="link">Page Link</t:pageLink>
</t:container>

...

There are still cases where you want to use the "inherit:" binding prefix. For example, if you have several components that need to share a parameter, then you must do it the Tapestry 5.0 way: a true parameter on the outer component, and "inherit:" bindings on the embedded components. You can follow a similar pattern to rename a parameter in the outer component.

Scrollbar