"Hello, world" Explained

A minimal, templated, Tapestry application needs only three files. For example, to produce this page:

Also in this page, towards the bottom, we use three components:

References: Apache Tapestry in Wikipedia, servlet, Deployment Descriptor.

Home


<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<body style="margin: 10px;">

    <h3>"Hello, ${username}" Explained</h3> 
    
    <p>A minimal, templated, Tapestry application needs only three files. For example, to produce this page:</p>
    
    <ul>
        <li><strong>HelloWorldExplained.tml</strong> 
            An (X)HTML template for the /helloworldexplained page. Tapestry templates can contain any well-formed (X)HTML markup.</li>
        <li><strong>HelloWorldExplained.java</strong> 
            A page class associated with the template. Here it merely provides a <em>username</em> property that the template can access.</li>
        <li><strong>web.xml</strong> 
            A servlet application deployment descriptor which installs Tapestry as a servlet filter.</li>
    </ul>

    <p>Also in this page, towards the bottom, we use three <em>components</em>:</p>
    
    <ul>
        <li><strong>PageLink</strong> is a core Tapestry component. It outputs an HTML link to another page.</li>
        <li><strong>TabGroup</strong> is a custom component provided by JumpStart. It outputs the tabs you see below.</li>
        <li><strong>SourceCodeTab</strong> is a custom component provided by JumpStart. It outputs a source file as HTML.</li>
    </ul>
    
    References: 
    <a href="http://en.wikipedia.org/wiki/Apache_Tapestry">Apache Tapestry in Wikipedia</a>, 
    <a href="http://en.wikipedia.org/wiki/Java_servlet">servlet</a>,
    <a href="http://en.wikipedia.org/wiki/Deployment_Descriptor">Deployment Descriptor</a>.<br/><br/>
    
    <t:pagelink page="Index">Home</t:pagelink><br/><br/>

    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/HelloWorldExplained.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/HelloWorldExplained.java"/>
        <t:sourcecodetab src="/web/src/main/webapp/WEB-INF/web.xml"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages;

/** A page class (automatically associated with the template file of the same name). */
public class HelloWorldExplained {
    
    /** An ordinary getter. */ 
    public String getUsername() {
        return "world";
    }
    
}


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <display-name>Tapestry JumpStart</display-name>

    <!-- Tell Tapestry where to look for pages, components, mixins, and services. -->

    <context-param>
        <param-name>tapestry.app-package</param-name>
        <param-value>jumpstart.web</param-value>
    </context-param>

    <!-- Tell the servlet container that we want a filter, call it "app", and it must be a TapestryFilter. -->

    <filter>
        <filter-name>app</filter-name>
        <filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
    </filter>

    <!-- Tell the servlet container to feed all requests through the above filter. -->

    <filter-mapping>
        <filter-name>app</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>