<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- We need a doctype to allow us to use special characters like
We use a "strict" DTD to make IE follow the alignment rules. -->
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<body class="container">
<h3>@Component</h3>
Working with a web designer, you may prefer to provide them a template without the clutter of the Tapestry parameter bindings.<br/>
Tapestry provides an alternative. Instead of this...
<div class="eg">
<code><t:pagelink page="Index">Home</pagelink></code>
</div>
...you can use invisible instrumentation (explained in the Previewable Templates example) and just the component id, like this...
<div class="eg">
<code><a t:id="home" href="#">Home</a></code>
</div>
...and move the parameter bindings into the class, with the <code>@Component</code> annotation, like this...
<div class="eg">
<code>@Component(id = "home", parameters = {"page=Index"})</code><br/>
<code>private PageLink index;</code>
</div>
The component id ties them together. Here it is in action:
<div class="eg">
<a t:id="home" href="#">Home</a>
</div>
Caution: parameter bindings specified in the annotation take precedence over the template. In this example we specified
a binding for the <code>page</code> parameter, so we do not specify it in the template too. Bindings specified
in the template are ignored if they conflict (case insensitive) with bindings from @Component.<br/><br/>
<strong>Which is best?</strong> Once again, the choice is yours. The first style keeps the component and parameter
information together in one place, which programmers may prefer. The second style removes clutter from the template,
which web designers may prefer.<br/><br/>
In JumpStart we use the first style.<br/><br/>
References:
<a href="http://tapestry.apache.org/component-classes.html#ComponentClasses-EmbeddedComponents">Embedded Components</a>,
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/annotations/Component.html">@Component</a>.
<br/><br/>
<t:tabgroup>
<t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/lang/AtComponent.tml"/>
<t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/lang/AtComponent.java"/>
<t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/olive.css"/>
</t:tabgroup>
</body>
</html>