5.3. Page Specification

Home.page. 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE page-specification
    PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
    "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">

<page-specification class="devguide.personalizedwelcome.Registration" 1 >

    <property-specification name="user" type="devguide.personalizedwelcome.User" 
    	initial-value="new devguide.personalizedwelcome.User()" /> 2 
    
    <component id="registrationForm" type="Form"> 3 
        <binding name="listener" expression="listeners.register"/> 4 
    </component>
    
    <component id="titleLabel" type="Insert">
        <message-binding name="value" key="label.title"/> 5 
    </component>

    <component id="firstNameLabel" type="Insert">
    </component>
    
    <component id="firstName" type="TextField">
        <binding name="value" expression="user.firstName"/>
    </component>
        
    <component id="lastNameLabel" type="Insert">
        <static-binding name="value" value="Last Name"/> 6 
    </component>

</page-specification>

1

The page class here is a user defined class (devguide.personalizedwelcome.Registration).

2

Definition of the transient property, user, to be created in the Registration class. The initial value of the property will be a new instance of the class User.

3

Explicit component declaration.

[Note]Note
Form is an enclosing component that encloses all other Tapestry form components.

4

Dynamic binding. The OGNL expression here is the name of the listener method, in the Registration class, to be invoked when the form is submitted.

[Tip]Tip
Listeners, in Tapestry, can be created simply by following a pattern for the listener method signature. Any method with the signature pattern, public void listenerMethod(IRequestCycle cycle), is automatically enhanced to implement IActionListener and added to the special listeners property map in AbstractComponent, by Tapestry!

5

Message binding.

6

Static binding.

Welcome.page. 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE page-specification
    PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
    "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">

<page-specification class="devguide.personalizedwelcome.Registration" 1 >
    
    <property-specification name="user" type="devguide.personalizedwelcome.User" 
    	initial-value="new devguide.personalizedwelcome.User()" />

    <component id="userName" type="Insert">
        <binding name="value">
            user.title + " " + user.firstname + " " + user.lastName" 2 
        </binding>
    </component>

</page-specification>

1

The page class is shared between the Home page and the Welcome page.

2

The dynamic OGNL expression.

[Tip]Tip
Expressions may be specified as the expression attribute value or alternatively as the body of the <binding> element as shown here. This is a helpful alternative when the expression is complex. This alternative expression may also be enclosed in a CDATA block to avoid any XML clashes.

[Note]Note
The specification here does not specify the page template explicitly. Whenever the template is not specified, Tapestry assumes the template name to be the name of the page with the appropriate extension and the location is identified via a methodical search as specified in the DefaultTemplateSource. So here, Tapestry assumes the template name to be Home.html.