Delegate to Renderable

This is an alternative to the approach in the Delegate to Block example. Here we use MarkupWriter to produce Renderables.
This is Renderable A.
This is Renderable B.
This is Renderable C.
This is Renderable B.
This is Renderable A.
This approach gives fine control over what's rendered. However, it cannot make use of informal parameters.

References: Delegate, Renderable, MarkupWriter, Switching Cases, Principle 1 - Static Structure, Dynamic Behavior.

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>Delegate to Renderable</h3>

    This is an alternative to the approach in the Delegate to Block example. Here we use MarkupWriter to produce Renderables.

    <div class="eg">
        <t:delegate to="a"/>
        <t:delegate to="b"/>
        <t:delegate to="c"/>
        <t:delegate to="b"/>
        <t:delegate to="a"/>
    </div>
    
    This approach gives fine control over what's rendered. However, it cannot make use of informal parameters.<br/><br/>  
    
    References: 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/Delegate.html">Delegate</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/Renderable.html">Renderable</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/MarkupWriter.html">MarkupWriter</a>, 
    <a href="http://tapestry.apache.org/switching-cases.html">Switching Cases</a>, 
    <a href="http://tapestry.apache.org/principles.html#Principles-Principle1StaticStructure%2CDynamicBehavior">Principle 1 - Static Structure, Dynamic Behavior</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/DelegateToRenderable.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/lang/DelegateToRenderable.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/plain.css"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.lang;

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

@Import(stylesheet = "css/examples/plain.css")
public class DelegateToRenderable {

    @Property(write = false)
    private final Renderable a = new Renderable() {
        public void render(MarkupWriter writer) {
            writer.element("div", "style", "margin: 2px; padding: 10px; background-color: #f8f8f8;");
            writer.write("This is Renderable A.");
            writer.end();
        }
    };

    @Property(write = false)
    private final Renderable b = new Renderable() {
        public void render(MarkupWriter writer) {
            writer.element("div", "style", "margin: 2px; padding: 10px; background-color: #f0f0f0;");
            writer.write("This is Renderable B.");
            writer.end();
        }
    };

    @Property(write = false)
    private final Renderable c = new Renderable() {
        public void render(MarkupWriter writer) {
            writer.element("div", "style", "margin: 2px; padding: 10px; background-color: #e8e8e8;");
            writer.write("This is Renderable C.");
            writer.end();
        }
    };

}


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