tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Tapestry > Component Cheat Sheet
Date Tue, 23 Aug 2011 15:24:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/12/_/styles/combined.css?spaceKey=TAPESTRY&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Component+Cheat+Sheet">Component
Cheat Sheet</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~demey.emmanuel@gmail.com">DEMEY
Emmanuel</a>
    </h4>
        <br/>
                         <h4>Changes (3)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >{float:right|background=#eee} <br>{contentbylabel:title=Related
Articles|showLabels=false|showSpace=false|space=@self|labels=component-classes,component-templates,components}
<br></td></tr>
            <tr><td class="diff-unchanged" >{float} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
<br></td></tr>
            <tr><td class="diff-unchanged" >There&#39;s a lot of documentation
scattered about describing the various annotations and methods you can add to Tapestry page
and component classes.  This is not an [exhaustive list|Annotations], but rather it covers
some of the the more common scenarios. <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{note} <br>Use of @Service is
discouraged. If marker annotations are available, that is preferred. <br></td></tr>
            <tr><td class="diff-unchanged" >{note} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. @InjectComponent <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h3. @InjectContainer <br> <br></td></tr>
            <tr><td class="diff-unchanged" >Injects the container of a component
or, when used in a mixin, injects the component the mixin is attached to. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. @InjectPage <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{note} <br></td></tr>
            <tr><td class="diff-changed-lines" >An alternative to @OnEvent is
the naming convention <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{on}}_EventName_</span>
<span class="diff-added-words"style="background-color: #dfd;">{{on{}}}{_}EventName_</span>
or <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{on}}_EventName_{{From}}_ComponentId_.</span>
<span class="diff-added-words"style="background-color: #dfd;">{{on{}}}{_}EventName{_}{{{}From{}}}{_}ComponentId_.</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >{note} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h3. @SupportsInformalParameters <br>
<br></td></tr>
            <tr><td class="diff-unchanged" >Marks the component as allowing informal
parameters (extra attributes in the template that do not match formally declared parameters).
Normally, informal parameters are simply discarded. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>The method ComponentResources.renderInformalParameters()
can be used to include the informal parameters within the element rendered by your component.
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Marks the page as accessible only
via secure (HTTPs).  Any attempt to access the page via standard HTTP will be redirected to
the HTTPs version. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >By default, the @Secure annotation
is ignored in development mode and only active in production mode. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. Render Phase Methods
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Render phase methods are close cousins
to event handler methods; they are how Tapestry integrates your code into the overall rendering
of the page.  For each render phase, there&#39;s an annotation and corresponding naming
convention to define a render phase method: <br> <br></td></tr>
            <tr><td class="diff-unchanged" >|| Annotation || Method Name || General
Use || <br></td></tr>
            <tr><td class="diff-unchanged" >| @SetupRender | setupRender() | Initializes
the component before rendering | <br>| @BeginRender | beginRender() | Renders the element
and primary attributes of the component | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >A render phase method may also return
false, in which case the flow continues to an alternate render phase, as per the chart in
the [Component Rendering] reference page. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >The most common cases: <br></td></tr>
            <tr><td class="diff-unchanged" >* return {{false}} from @BeginRender
to skip the rendering of the component&#39;s template and/or body, and continue with @AfterRender
<br>* return {{false}} from @AfterRender to return to @BeginRender (this is used in
component, such as {{Loop}}, that render themselves multiple times) <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Pages have a life cycle and this is
represented by a _third_ set of annotations or method naming conventions. Life cycle methods
may appear on a page or any component of a page. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >|| Annotation || Method Name || Description
||
| @PageLoaded | pageLoaded() | The page instance has been loaded but not yet attached for
the first time. |
| @PageAttached | pageAttached() | The page is being used within a particular request. This
occurs before the activate event. |
| @PageReset | pageReset() | See notes below. |
| @PageDetached | pageDetached() | End of request notification. | <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Page life cycle methods
may be any visibility. They must take no parameters and return void. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>The @PageReset life cycle
is new in Tapestry 5.2.  It will be invoked on a page render request when linked to from some
other page of the application. This is to allow the page to reset its state, if any, when
a user returns to the page from some other part of the application. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>h2. Configuring Annotations <br> <br>The SymbolProvider service has
two interfaces : FactoryDefaults and ApplicationDefaults. Tapestry provides 2 annotations
in order to define which implementation you want to override in your AppModule :&amp;nbsp;
<br> <br>* @FactoryDefaults <br>{code:title=AppModule with @FactoryDefaults}@Contribute(SymbolProvider.class)
<br>@FactoryDefaults <br>public void setParam(MappedConfiguration&lt; String,
String&gt; configuration){ <br>  configuration.add(SymbolConstants.PRODUCTION_MODE,
&quot;false&quot;); <br>}{code} <br>* @ApplicationDefaults <br>{code:title=AppModule
with @ApplicationDefaults}@Contribute(SymbolProvider.class) <br>@ApplicationDefaults
<br>public void setParam(MappedConfiguration&lt; String, String&gt; configuration){
<br>  configuration.add(SymbolConstants.PRODUCTION_MODE, &quot;false&quot;);
<br>}{code} <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div class='navmenu' style='float:right; background:#eee; margin:3px; padding:3px'><table
class="tableview" width="100%">
            <tr><th style="padding: 3px 3px 3px 0px">Related Articles</th></tr>
                        <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Component+Parameters">Component
Parameters</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Component+Templates">Component
Templates</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Component+Reference">Component
Reference</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Page+And+Component+Classes+FAQ">Page
And Component Classes FAQ</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Component+Classes">Component
Classes</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Templating+and+Markup+FAQ">Templating
and Markup FAQ</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Component+Libraries">Component
Libraries</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Component+Cheat+Sheet">Component
Cheat Sheet</a>
        
                                            </td>
        </tr>
            </table>
</div>
<p>There's a lot of documentation scattered about describing the various annotations
and methods you can add to Tapestry page and component classes.  This is not an <a href="/confluence/display/TAPESTRY/Annotations"
title="Annotations">exhaustive list</a>, but rather it covers some of the the more
common scenarios.</p>

<h2><a name="ComponentCheatSheet-FieldInjectionAnnotations"></a>Field Injection
Annotations</h2>

<p>Main articles: <a href="/confluence/display/TAPESTRY/Component+Classes" title="Component
Classes">Component Classes</a>, <a href="/confluence/display/TAPESTRY/Injection"
title="Injection">Injection</a>, <a href="/confluence/display/TAPESTRY/Annotations"
title="Annotations">Annotations</a></p>

<h3><a name="ComponentCheatSheet-@Inject"></a>@Inject</h3>

<p>@Inject is the Swiss Army knife of annotations; it's designed to connect your component
to services, resources, and other objects. See <a href="/confluence/display/TAPESTRY/Injection"
title="Injection">Injection</a>.</p>

<h4><a name="ComponentCheatSheet-ServiceInjection"></a>Service Injection</h4>

<p>In most cases, the injected value is a service; the service is located by type. If
there are ambiguities, caused by multiple services implementing the same interface, you'll
see injection exceptions. You can resolve those exceptions by adding marker annotations to
select a specific service, or by adding @Service to specify the specific service ID you want.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>Use of @Service is discouraged.
If marker annotations are available, that is preferred.</td></tr></table></div>

<h3><a name="ComponentCheatSheet-@InjectComponent"></a>@InjectComponent</h3>

<p>Injects a component from this component's template into this component's class. Injecting
a component is based on the component's ID, which should match the field name. However, the
value attribute of the @InjectComponent annotation can be specified as well, this takes precedence
over the field name.</p>

<p>It is common to inject a component in order to obtain its client-side ID (used when
generating client-side JavaScript).</p>

<h3><a name="ComponentCheatSheet-@InjectContainer"></a>@InjectContainer</h3>

<p>Injects the container of a component or, when used in a mixin, injects the component
the mixin is attached to.</p>

<h3><a name="ComponentCheatSheet-@InjectPage"></a>@InjectPage</h3>

<p>Injects a page of the application. Normally, the page to inject is identified based
on the field type. The value attribute can be specified, in which case the page to be injected
is identified by name.</p>

<h3><a name="ComponentCheatSheet-@Environmental"></a>@Environmental</h3>

<p>Injects an <a href="/confluence/display/TAPESTRY/Environmental+Services" title="Environmental
Services">environmental object</a>; such objects are request scoped but may be overridden
at any time using the methods of the Environment service. Environmental objects are used to
allow outer components to communicate with components they enclose.</p>

<p>Most often, @Environmental is used with type JavaScriptSupport, which is used to
add JavaScript code and libraries to the rendered page.</p>

<h2><a name="ComponentCheatSheet-FieldBehaviorAnnotations"></a>Field Behavior
Annotations</h2>

<p>Main articles: <a href="/confluence/display/TAPESTRY/Component+Classes" title="Component
Classes">Component Classes</a>, <a href="/confluence/display/TAPESTRY/Annotations"
title="Annotations">Annotations</a></p>

<h3><a name="ComponentCheatSheet-@PageActivationContext"></a>@PageActivationContext</h3>

<p>This annotation is allowed on a <em>single</em> field; the value of the
field will be included in URLs for the page as the page's activation context. This is an alternative
to implementing event handler methods<br/>
for the activate and passivate events directly.</p>

<h3><a name="ComponentCheatSheet-@Parameter"></a>@Parameter</h3>

<p>Marks the field as a component parameter. Attributes of the annotation allow the
parameter to be marked as required or optional.  If the parameter value will typically be
a literal string (for example, the title parameter to a Layout component), you should add
<tt>defaultPrefix=BindingConstants.LITERAL</tt> to the annotation so that users
of the component won't have to use the "literal:" binding prefix with the parameter. See <a
href="/confluence/display/TAPESTRY/Component+Parameters" title="Component Parameters">Component
Parameters</a></p>

<h3><a name="ComponentCheatSheet-@Persist"></a>@Persist</h3>

<p>Marks the field as a persistent value, one that maintains its value between requests.
The default <em>strategy</em> is to simply store the value in the session (which
is created as needed). Other strategies can be specified by name as the value attribute. See
<a href="/confluence/display/TAPESTRY/Persistent+Page+Data" title="Persistent Page Data">Persistent
Page Data</a>.</p>

<h3><a name="ComponentCheatSheet-@Property"></a>@Property</h3>

<p>Directs Tapestry to automatically generate a getter and a setter for the field, converting
it to a JavaBeans property than can be referenced from the template.</p>

<h3><a name="ComponentCheatSheet-@SessionState"></a>@SessionState</h3>

<p>Marks the field as a Session State Object (SSO).  SSOs store global data, and can
be injected into any page or component. The SSOs are stored in the session, using a key based
on the Java type. SSOs are usually created on demand, but the <tt>create</tt>
attribute can turn this off. See <a href="/confluence/display/TAPESTRY/Session+Storage"
title="Session Storage">Session Storage</a></p>

<h3><a name="ComponentCheatSheet-@SessionAttribute"></a>@SessionAttribute</h3>

<p>In Tapestry 5.2 and later, marks the field as a Session Attribute.  Like Session
State Objects (SSO), a Session Attribute is stored in the session, however Session Attributes
are stored by using a name you choose rather than based on the Java type. See <a href="/confluence/display/TAPESTRY/Session+Storage"
title="Session Storage">Session Storage</a>.</p>

<h3><a name="ComponentCheatSheet-@ActivationRequestParameter"></a>@ActivationRequestParameter</h3>

<p>Fields with this annotation will be encoded into URLs as query parameters, in much
the same way as data is encoded into the URL path. The query parameter name matches the field
name, unless the value attribute is specified.</p>

<h2><a name="ComponentCheatSheet-MethodAnnotations"></a>Method Annotations</h2>

<p>Main articles: <a href="/confluence/display/TAPESTRY/Component+Classes" title="Component
Classes">Component Classes</a>, <a href="/confluence/display/TAPESTRY/Annotations"
title="Annotations">Annotations</a></p>

<h3><a name="ComponentCheatSheet-@OnEvent"></a>@OnEvent</h3>

<p>Marks a method as an event handler method. Such methods may have any visibility,
and typically use package private visibility (that is, no visibility keyword at all). By default,
the method will handle the action event from any component; the value attribute controls the
matched event, and the component annotation is used to limit the event source.</p>

<p>An event handler method may take parameters, corresponding the event context associated
with the event, such as the page activation context for the activate event.  The method will
not be invoked if it defines more parameters than there are values in the context.</p>

<p>The @RequestParameter annotation can be used on parameters, in which case the parameters
value comes from a request query parameter, and not from the event context.</p>

<p>Events fired on a component bubble up the component's container. Return a non-null
value to cancel event bubbling. What values may be returned from an event handler method is
dependent on the type of event.</p>

<p>You may also return true to indicate that the event is handled and bubbling should
cancel (even for events that do not permit a return value).</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>An alternative to @OnEvent is
the naming convention <tt>on</tt><em>EventName</em> or <tt>on</tt><em>EventName</em><tt>From</tt><em>ComponentId</em>.</td></tr></table></div>

<h3><a name="ComponentCheatSheet-@Log"></a>@Log</h3>

<p>Marks the method to be logged for debugging purposes: method entry (with parameters)
and exit (with return value) will be logged at debug level, as will any thrown exception.
This is primarily for debugging purposes. The Logger name will match the component classes'
fully qualified class name.</p>

<h3><a name="ComponentCheatSheet-@CommitAfter"></a>@CommitAfter</h3>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>The support for this annotation
comes from the <a href="/confluence/display/TAPESTRY/Hibernate" title="Hibernate">tapestry-hibernate</a>
module.</td></tr></table></div>

<h3><a name="ComponentCheatSheet-@Cached"></a>@Cached</h3>

<p>Used on methods that perform expensive operations, such as database queries. The
first time such a method is invoked, the return value is cached. Future invocations of the
same method return the cached value.</p>

<p>The result cache is per-request and is discarded at the end of the request.</p>

<p>@Cached only works on methods that take no parameters.</p>

<h2><a name="ComponentCheatSheet-ParameterAnnotations"></a>Parameter Annotations</h2>

<p>Main article: <a href="/confluence/display/TAPESTRY/Component+Parameters" title="Component
Parameters">Component Parameters</a></p>

<h3><a name="ComponentCheatSheet-@RequestParameter"></a>@RequestParameter</h3>

<p>Used with event handler methods to get the value for the parameter from a request
query parameter.</p>

<h2><a name="ComponentCheatSheet-TypeAnnotations"></a>Type Annotations</h2>

<h3><a name="ComponentCheatSheet-@Events"></a>@Events</h3>

<p>Lists the names of events that may be fired from within this component; used for
documentation purposes only.</p>

<h3><a name="ComponentCheatSheet-@Import"></a>@Import</h3>

<p>Allows JavaScript libraries and CSS stylesheet files to be includes in the rendered
page. Each such file is added to the page only once, in the order in which the page renders.</p>

<p>It is allowed to use symbol expansions (with the <tt>${...</tt>} syntax)
inside a library or stylesheet path.</p>

<p>@Import may also be applied to individual methods, in which case the import operation
only occurs when the method is invoked.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>When specifying a file to import,
you'll often use the prefix <tt>context:</tt> to indicate that the file is stored
in the web application context, and not on the classpath.  Relative paths will be on the classpath,
relative to the Java class.</td></tr></table></div>

<h3><a name="ComponentCheatSheet-@SupportsInformalParameters"></a>@SupportsInformalParameters</h3>

<p>Marks the component as allowing informal parameters (extra attributes in the template
that do not match formally declared parameters). Normally, informal parameters are simply
discarded.</p>

<p>The method ComponentResources.renderInformalParameters() can be used to include the
informal parameters within the element rendered by your component.</p>

<h3><a name="ComponentCheatSheet-@Secure"></a>@Secure</h3>

<p>Marks the page as accessible only via secure (HTTPs).  Any attempt to access the
page via standard HTTP will be redirected to the HTTPs version.</p>

<p>By default, the @Secure annotation is ignored in development mode and only active
in production mode.</p>

<h2><a name="ComponentCheatSheet-RenderPhaseMethods"></a>Render Phase Methods</h2>

<p>Main article: <a href="/confluence/display/TAPESTRY/Component+Rendering" title="Component
Rendering">Component Rendering</a></p>

<p>Render phase methods are close cousins to event handler methods; they are how Tapestry
integrates your code into the overall rendering of the page.  For each render phase, there's
an annotation and corresponding naming convention to define a render phase method:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Annotation </th>
<th class='confluenceTh'> Method Name </th>
<th class='confluenceTh'> General Use </th>
</tr>
<tr>
<td class='confluenceTd'> @SetupRender </td>
<td class='confluenceTd'> setupRender() </td>
<td class='confluenceTd'> Initializes the component before rendering </td>
</tr>
<tr>
<td class='confluenceTd'> @BeginRender </td>
<td class='confluenceTd'> beginRender() </td>
<td class='confluenceTd'> Renders the element and primary attributes of the component
</td>
</tr>
<tr>
<td class='confluenceTd'> @AfterRender </td>
<td class='confluenceTd'> afterRender() </td>
<td class='confluenceTd'> Closes the element started in beginRender() </td>
</tr>
<tr>
<td class='confluenceTd'> @CleanupRender </td>
<td class='confluenceTd'> cleanupRender() </td>
<td class='confluenceTd'> Performs cleanup after all rendering of the component finishes
</td>
</tr>
</tbody></table>
</div>


<p>Render phase methods either take no parameters, or take a single parameter of type
MarkupWriter.</p>

<p>Render phase methods may return <tt>void</tt>, a <tt>boolean</tt>,
or a <em>renderable object</em>.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>Generally, a <tt>renderable
object</tt> is a <tt>Block</tt> or a component. The object is pushed onto
the stack of rendering operations, temporarily replacing the current component as the object
to be rendered.</td></tr></table></div>

<p>Returning true is the same as returning void; it means that the component should
follow the typical flow:</p>

<ul>
	<li>@SetupRender</li>
	<li>@BeginRender</li>
	<li>Render the component's template, if any</li>
	<li>Render the component's body</li>
	<li>@AfterRender</li>
	<li>@CleanupRender</li>
</ul>


<p>If a component has a template, the component's body will only render if the template
contains a &lt;t:body&gt; element.  If a component has no template, then it will always
render its body (between @BeginRender and @AfterRender).</p>

<p>A render phase method may also return false, in which case the flow continues to
an alternate render phase, as per the chart in the <a href="/confluence/display/TAPESTRY/Component+Rendering"
title="Component Rendering">Component Rendering</a> reference page.</p>

<p>The most common cases:</p>
<ul>
	<li>return <tt>false</tt> from @BeginRender to skip the rendering of the
component's template and/or body, and continue with @AfterRender</li>
	<li>return <tt>false</tt> from @AfterRender to return to @BeginRender (this
is used in component, such as <tt>Loop</tt>, that render themselves multiple times)</li>
</ul>


<h2><a name="ComponentCheatSheet-PageLifeCycleMethods"></a>Page Life Cycle
Methods</h2>

<p>Main article: <a href="/confluence/display/TAPESTRY/Page+Life+Cycle" title="Page
Life Cycle">Page Life Cycle</a></p>

<p>Pages have a life cycle and this is represented by a <em>third</em> set
of annotations or method naming conventions. Life cycle methods may appear on a page or any
component of a page.</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Annotation </th>
<th class='confluenceTh'> Method Name </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> @PageLoaded </td>
<td class='confluenceTd'> pageLoaded() </td>
<td class='confluenceTd'> The page instance has been loaded but not yet attached for
the first time. </td>
</tr>
<tr>
<td class='confluenceTd'> @PageAttached </td>
<td class='confluenceTd'> pageAttached() </td>
<td class='confluenceTd'> The page is being used within a particular request. This occurs
before the activate event. </td>
</tr>
<tr>
<td class='confluenceTd'> @PageReset </td>
<td class='confluenceTd'> pageReset() </td>
<td class='confluenceTd'> See notes below. </td>
</tr>
<tr>
<td class='confluenceTd'> @PageDetached </td>
<td class='confluenceTd'> pageDetached() </td>
<td class='confluenceTd'> End of request notification. </td>
</tr>
</tbody></table>
</div>


<p>Page life cycle methods may be any visibility. They must take no parameters and return
void.</p>

<p>Page life cycle methods are of lower importance starting in Tapestry 5.2, since page
instances are now shared across threads, rather than pooled.</p>

<p>The @PageReset life cycle is new in Tapestry 5.2.  It will be invoked on a page render
request when linked to from some other page of the application. This is to allow the page
to reset its state, if any, when a user returns to the page from some other part of the application.</p>

<h2><a name="ComponentCheatSheet-ConfiguringAnnotations"></a>Configuring
Annotations</h2>

<p>The SymbolProvider service has two interfaces : FactoryDefaults and ApplicationDefaults.
Tapestry provides 2 annotations in order to define which implementation you want to override
in your AppModule :&nbsp;</p>

<ul>
	<li>@FactoryDefaults
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>AppModule with @FactoryDefaults</b></div><div
class="codeContent panelContent">
<pre class="code-java">@Contribute(SymbolProvider.class)
@FactoryDefaults
<span class="code-keyword">public</span> void setParam(MappedConfiguration&lt;
<span class="code-object">String</span>, <span class="code-object">String</span>&gt;
configuration){
  configuration.add(SymbolConstants.PRODUCTION_MODE, <span class="code-quote">"<span
class="code-keyword">false</span>"</span>);
}</pre>
</div></div></li>
	<li>@ApplicationDefaults
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>AppModule with @ApplicationDefaults</b></div><div
class="codeContent panelContent">
<pre class="code-java">@Contribute(SymbolProvider.class)
@ApplicationDefaults
<span class="code-keyword">public</span> void setParam(MappedConfiguration&lt;
<span class="code-object">String</span>, <span class="code-object">String</span>&gt;
configuration){
  configuration.add(SymbolConstants.PRODUCTION_MODE, <span class="code-quote">"<span
class="code-keyword">false</span>"</span>);
}</pre>
</div></div></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Component+Cheat+Sheet">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24184518&revisedVersion=13&originalVersion=12">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message