tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Taylor <DavidVTay...@cox.net>
Subject Taming missing page errors
Date Tue, 15 Mar 2005 12:40:48 GMT
While Tapestry is a great framework, it has a few rough edges. One of
these is how it handles common problems such as missing pages. Throwing
an ApplicationRuntimeException is a bit unfriendly for a common error
and leaves users with a sense that the application is seriously broken.
While this is definitely more informative than a blank page (I hate it
when that happens), it is preferable to interpret common error
conditions and display a more user-friendly message.

After think about this issue for a while, I decided to find a way to
make Tapestry handle missing pages better. Poking around in the tapestry
code I discovered this could be accomplished with a custom
SpecificationResolverDelegate. When Tapestry is unable to find a page,
it calls the findPageSpecification method of the resolver delegate. By
simply throwing a PageRedirectException, the error can be forwarded onto
a custom error page. The code below shows the key piece of logic. I took
this one step further and stored the error information into the request
for use in the custom error page. This method of passing error
information also just  happens to match the way servlet containers pass
data to error pages registered in web.xml.  I now have a single error
page that works for both purposes.

This approach has already found its way into a couple of production
applications. If anyone is interested I would be happy to share my code.
I would also be interested in what other people are doing for their
Tapestry error pages.

    * Throws a Page Redirect exception to report that a requested page
    * specification could not be found. The target error page name is
    * the value configured in the application specification file or the
   public IComponentSpecification findPageSpecification(IRequestCycle
           INamespace namespace, String simplePageName) {

       // Determine the name of the error page to display
       IApplicationSpecification appSpec =
       String errorPageName =

       if (Tapestry.isBlank(errorPageName))

       // Handle special case where the error page itself cannot be found
       if (simplePageName.equals(errorPageName))
           return null;

       // Store information about the error in the request
       HttpServletRequest request = cycle.getRequestContext().getRequest();
       HttpServletResponse response =
       request.setAttribute("javax.servlet.error.status_code", new
       request.setAttribute("javax.servlet.error.message", "Unable to
find the requested page");

       // Set http response code to 404
       throw new PageRedirectException(simplePageName, null, null,

Here is how the class is registered in the application specification:

 <!-- Register an extension to handle missing page errors -->
 <extension name="org.apache.tapestry.specification-resolver-delegate"

To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org

View raw message