Better Output

As Tapestry generates, or renders, a page, it will call the page's setupRender() method if the page has one.
When a field is annotated with @Property, Tapestry creates getter and setter methods for it at runtime.

server time: Fri Mar 29 12:13:39 UTC 2024.
server time: Fri Mar 29 12:13:39 UTC 2024.
server time: Fri Mar 29 12:13:39 UTC 2024.

Refresh
In the previous example we used getMessage() to generate a message. In this example we used setupRender() to generate a value for the message field which is annotated with @Property. The result is that despite being referenced 3 times, message is generated only once.

References: SetupRender, @Property, Context: Bindings, Expansions, Binding Expressions.

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>Better Output</h3>

    As Tapestry generates, or <em>renders</em>, a page, it will call the page's 
    <code>setupRender()</code> method if the page has one.<br/>
    When a field is annotated with <code>@Property</code>, Tapestry creates getter and setter methods for it at runtime.<br/>
    
    <div class="eg">
        <p>
        ${message}<br/>
        ${message}<br/>
        ${message}<br/>
        </p>
        <t:pagelink t:page="examples/output/BetterOutput" href="#">Refresh</t:pagelink>
    </div>

    In the previous example we used <code>getMessage()</code> to generate a message. 
    In this example we used <code>setupRender()</code> to generate a value for the <code>message</code> field which is 
    annotated with <code>@Property</code>. The result is that despite being referenced 3 times, message is generated only once. <br/><br/>
    
    References: 
    <a href="http://tapestry.apache.org/component-rendering.html#ComponentRendering-SetupRender">SetupRender</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/annotations/Property.html">@Property</a>, 
    <a href="http://tapestry.apache.org/component-parameters.html#ComponentParameters-Context%3ABindings">Context: Bindings</a>, 
    <a href="http://tapestry.apache.org/component-templates.html#ComponentTemplates-Expansions">Expansions</a>, 
    <a href="http://tapestry.apache.org/component-parameters.html#ComponentParameters-bindingexpressions">Binding Expressions</a>.<br/><br/>
    
    <t:pagelink page="Index" href="#">Home</t:pagelink><br/><br/>

    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/output/BetterOutput.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/output/BetterOutput.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/olive.css"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.output;

import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Property;

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

    @Property
    private String message;

    void setupRender() {
        message = "server time: " + new java.util.Date() + ".";
    }

}


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