Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed bad links due to copy-paste from cwiki-test

...

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

...

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).

...

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>

...

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>

...