Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for 
change notification.

The following page has been changed by Carl:
http://wiki.apache.org/tapestry/Tapestry5HowToUseTapestryForCustomErrorPages

New page:
= How To Use Tapestry For Custom Error Pages =

''Note: This describes how to use a page in a Tapestry application to display 
custom 404 (and other) error messages. This is different to overriding the 
Exception report - for that, see [Tapestry5ExceptionPage].''

You can add custom pages to your web.xml using the error-page element - see 
[http://edocs.bea.com/wls/docs61/webapp/web_xml.html]. For a given error code 
or exception, the server will display the page at a given path.

For example, if you have a Tapestry page in your app called "Error404" you can 
add:

{{{
    <error-page>
        <error-code>404</error-code>
        <location>/error404</location>
    </error-page> 
}}}

(This assumes that your application is served as the root context.)

However, Tapestry5 is implemented as a servlet filter, which means that when 
this error page is served you actually get another 404 for your error page! By 
default, error pages aren't passed through the servlet filters.

In order to make this happen, you need to use a Servlet 2.4 spec container and 
web.xml file (the examples use 2.3). You also need to add dispatcher 
configuration to the filter definition to sent errors as well as request 
through the filter.

Here is the updated web.xml which will enable you to use a Tapestry5 page for 
your error page:

{{{

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

<web-app xmlns="http://java.sun.com/xml/ns/j2ee";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
    version="2.4">

    <display-name>MyApp</display-name>
    <context-param>
        <param-name>tapestry.app-package</param-name>
        <param-value>com.something.myapp</param-value>
    </context-param>
        
    <filter>
        <filter-name>app</filter-name>
        <filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>app</filter-name>
        <url-pattern>*</url-pattern>  
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    
    <error-page>
        <error-code>404</error-code>
        <location>/error404</location>
    </error-page> 
        
</web-app>

}}}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to