Annotations

Tapestry doesn't just look for particular method names, it also looks for particular method annotations. Here are some for phases:

Here are some other useful annotations:

Here is a demonstration:
message: "thisPageHasBeenRequested() called... beforeWeDoAnyRendering() called... ".
References: Annotations, Rendering Phases, SetupRender, CleanupRender, @Property, Logging.

Home


<!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 &nbsp; 
     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>Annotations</h3> 
    
    Tapestry doesn't just look for particular method names, it also looks for particular method annotations. Here are some for phases:<br/><br/>

    <ul>
        <li>
            <code>@OnEvent(value = EventConstants.ACTIVATE)</code>
            You can put this annotation on a method instead of naming the method <em>onActivate</em>.
        </li>
        <li>
            <code>@SetupRender</code>
            You can put this annotation on a method instead of naming the method <em>setupRender</em>.
        </li>
        <li>
            <code>@CleanupRender</code>
            You can put this annotation on a method instead of naming the method <em>cleanupRender</em>.
        </li>
    </ul>
    
    Here are some other useful annotations:<br/><br/>

    <ul>
        <li>
            <code>@Property</code>
            A field annotation. Tapestry will invisibly provide a getter and setter for the field. You can make the property
            read-only or write-only - see <a
                href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/annotations/Property.html">@Property</a>.
        </li>

        <li>
            <code>@Log</code>
            A method annotation. Tapestry will write to the log, at DEBUG level, as it enters and exits the method. Tapestry will
            also log the parameter values and the method's return value.<br />
        </li>
    </ul>
    
    Here is a demonstration:<br/>
    
    <div class="eg">
        message: "${message}".
    </div>

    References: 
    <a href="http://tapestry.apache.org/annotations.html">Annotations</a>, 
    <a href="http://tapestry.apache.org/component-rendering.html#ComponentRendering-RenderingPhases">Rendering Phases</a>, 
    <a href="http://tapestry.apache.org/component-rendering.html#ComponentRendering-SetupRender">SetupRender</a>, 
    <a href="http://tapestry.apache.org/component-rendering.html#ComponentRendering-CleanupRender">CleanupRender</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/annotations/Property.html">@Property</a>, 
    <a href="http://tapestry.apache.org/logging.html">Logging</a>.<br/><br/>

    <t:pagelink page="Index">Home</t:pagelink><br/><br/>
    
    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/lang/Annotations.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/lang/Annotations.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/olive.css"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.lang;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.CleanupRender;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

@Import(stylesheet = "css/examples/olive.css")
public class Annotations {

    @Property
    private String message;
    
    @Inject
    private Logger logger;

    @OnEvent(value = EventConstants.ACTIVATE)
    void thisPageHasBeenRequested() {
        message = "thisPageHasBeenRequested() called... ";
        logger.info("thisPageHasBeenRequested() called... ");
    }

    @SetupRender
    void beforeWeDoAnyRendering() {
        message += "beforeWeDoAnyRendering() called... ";
        logger.info("beforeWeDoAnyRendering() called...");
    }

    @CleanupRender
    void tidyUp() {
        message += "tidyUp() called... ";
        logger.info("tidyUp() called...");
    }

}


.eg {
                margin: 20px 0;
                padding: 14px;
                color: olive;
                border: 1px solid #ddd;
                border-radius: 6px;
                -webkit-border-radius: 6px;
                -mox-border-radius: 6px;
}