Wiki Markup |
{scrollbar} |
Excerpt |
|
|
| Serving up a Tapestry page as your site's custom 404 response page |
Wiki Markup |
{float:right|background=""
{contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=@self|labels=errors}
{float} |
...
Simply upgrade your application web.xml to the 2.4 version, and make a couple of changes:
Code Block |
|
|
|
<?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>Cookbook</display-name>
<context-param>
<param-name>tapestry.app-package</param-name>
<param-value>com.example.cookbook</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>
|
...
We'll create a simple Error404 page, one that displays a message and (in development mode) displays the details about the incoming request.
Code Block |
|
|
|
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<head>
<title>Resource not found.</title>
</head>
<body>
<h1>Page or resource not found.</h1>
<t:if test="! productionMode">
<t:renderobject object="request"/>
</t:if>
</body>
</html>
|
...
Code Block |
|
|
|
package com.example.cookbook.pages;
import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.services.Request;
public class Error404
{
@Property
@Inject
private Request request;
@Property
@Inject
@Symbol(SymbolConstants.PRODUCTION_MODE)
private boolean productionMode;
}
|
...