Methods

As a page renders, it goes through phases. You can provide methods that Tapestry will call in those phases. Here are the most useful ones...

Here is a demonstration:
message: "onActivate() called... setupRender() called... getMessage() called... ".
Why is "cleanupRender() called..." missing from the message? Because the message is rendered BEFORE cleanupRender() is called. However, "cleanupRender() called..." will be in the log.

References: Rendering Phases, SetupRender, CleanupRender.

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>Methods</h3> 
    
    As a page renders, it goes through phases. You can provide methods that Tapestry will call in those phases.  
    Here are the most useful ones...<br/><br/>

    <ul>
        <li>
            <code>onActivate()</code>
            Tapestry will call it when a request from a browser involves your page. <br /> Behind the scenes, what happens is
            that Tapestry gets an instance of the page and triggers <em>activate</em> on it.
        </li>
        <li>
            <code>setupRender()</code>
            Tapestry will call it right before it starts rendering.
        </li>
        <li>
            <code>cleanupRender()</code>
            Tapestry will call it immediately after all the rendering has been done.
        </li>
    </ul>

    Here is a demonstration:
    
    <div class="eg">
        message: "${message}".
    </div>

    Why is "cleanupRender() called..." missing from the message? Because the message is rendered BEFORE 
    <code>cleanupRender()</code> is called. However, "cleanupRender() called..." will be in the log.<br/><br/> 
    
    References:
    <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>.<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/Methods.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/lang/Methods.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.annotations.Import;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

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

    private String message;

    @Inject
    private Logger logger;

    void onActivate() {
        message = "onActivate() called... ";
        logger.info("onActivate() called... ");
    }

    void setupRender() {
        message += "setupRender() called... ";
        logger.info("setupRender() called...");
    }

    public String getMessage() {
        message += "getMessage() called... ";
        logger.info("getMessage() called...");
        return message;
    }

    void cleanupRender() {
        message += "cleanupRender() called... ";
        logger.info("cleanupRender() called...");
    }

}


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