Chapter 7. Poutpourri!

Table of Contents

The Visit Object
The Home Page
The Guess Page
Limitations

So far, these examples have been a little bit cut-and-dried. Lets do a meatier example that uses a few more interesting components. Let's play Hangman!

Our Hangman application consists of four pages. The Home page allows a new game to be started, which includes selecting the difficulty of the game (how many wrong guesses you are allowed).

Figure 7.1. Hangman Home Page

The main page is the Guess page, where the partially filled out word is displayed, and the user can make guesses (from a shrinking list of possible letters):

Figure 7.2. Hangman Guess Page

After you give up, or when you make too many mistakes, you end up on the the Failed page:

Figure 7.3. Hangman Failed Page

But, if you guess all the letters, you are sent to the Success page:

Figure 7.4. Hangman Success Page

The Visit Object

The center of this application is an object that represents game, an object of class HangmanGame. This object is used to track the word being guessed, the letters that have been used, the number of misses and the letters that have been correctly guessed.

This object is a property of the visit object. What's the visit object? The visit object is a holder of all information about a single client's visit to your web application. It contains data and methods that are needed by the pages and components of your application.

The visit object is owned and created by the engine object. It is serialized and de-serialized with the engine.

The application specification includes a little extra segment at the bottom to specify the class of the visit object.

Figure 7.5. Hangman.application

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
  "-//Howard Ship//Tapestry Specification 1.1//EN" 
  "http://tapestry.sf.net/dtd/Tapestry_1_1.dtd">

<application name="Tapestry Hangman" engine-class="com.primix.tapestry.engine.SimpleEngine"> 

  <property name="com.primix.tapestry.visit-class">tutorial.hangman.Visit</property> 1

  <page name="Home" specification-path="/tutorial/hangman/Home.jwc"/>

  <page name="Guess" specification-path="/tutorial/hangman/Guess.jwc"/>

  <page name="Failed" specification-path="/tutorial/hangman/Failed.jwc"/>

  <page name="Success" specification-path="/tutorial/hangman/Success.jwc"/>

</application>    

1

This property specifies that the engine should instantiate an instance of tutorial.hangman.Visit when a visit object is first required. This is the default way in which the visit object is specified, though if the visit object doesn't have an empty constructor method, the engine method createVisit() must be implemented instead.

So, returning from that distraction, the game object is a property of the visit object, which is accessible from any page (via the page's visit property).