Determining the Page Class

When it comes time for Tapestry to instantiate a page, it must identify the Java class to instantiate.

Tapestry pages implement the IPage interface. Because this is a large interface, you will typically extends the BasePage base class (for HTML pages).

Typically, you will identify the page class within the page's specification, using the <page-specification> element's class attribute.

In many cases, however, the page specification is optional. Alternately, the class attribute may be omitted from the page specification. Tapestry takes the following steps to find the class for a page:

  • As indicated in the page specification
  • By searching the packages listed in the application specification (more below)
  • The application specification's org.apache.tapestry.default-page-class property
  • The global property org.apache.tapestry.default-page-class
The most useful of these is the second option, to search. For this step, Tapestry looks in the application specification for the org.apache.tapestry.page-class-packages <meta> property. This is a comma-seperated list of package names to search. The list of packages is optional, and the default Java package is searched last. Also, for this search, the page name is converted into a partial class name. For pages inside folders, the folder names are part of the package name, so page name admin/EditUser will be become admin.EditUser . So, if the prefix list is org.example.pages , then Tapestry will search for org.example.pages.admin.EditUser , then admin.EditUser (that is, in the default package). Only if those searches fail to locate a class does Tapestry continue to the next steps, using default page class names in the application specification and beyond. Note:

These steps are specified in the tapestry.page.PageClassProviderChain configuration point.

For simplicity, we described the search for application pages. For pages within a library, the process is the same, but it is the library's specification which is searched for the list of packages, and later, for the default page class name.

Component Classes

A similar search occurs for components (again, with the express desire that the class attribute of the <component-specification> not be used).

  • As defined by the component specification
  • In any package defined by the containing namespace's org.apache.tapestry.component-class-packages meta data property (if any)
  • In the default package
  • BaseComponent is the final default
Note: These steps are specified in the tapestry.page.ComponentClassProviderChain configuration point.