上网查了下Tabestry5的文档,大多都是把官网的文档拿来翻译,并没有做调式,这种不负责任的态度,很容易误导别人,这种文章不是帮人,而是害人,特别是经验不是丰富的兄弟姐妹。举个简单的例子,web.xml里面配置各filter,居然还是这样:
<filter>
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry.TapestryFilter</filter-class>
</filter>
实在搞不懂,这个最简单的问题也容易忽视。正确的是:
<filter>
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
</filter>
ok, 切入正题,下面我将详细的说下这个tutorial.
1. 环境
JDK: 1.6
TOMCAT:6.0以上,我的是6.0.26
tapestry:5.1.0.5,应该5.1以上都类似。
OS:32位WindowsXP Home edition.
IDE:eclipse 3.5(可选),我直接在tomcat安装目录下做的。
2. 建立目录结构
tabdemo
WEB-INF
classes
lib
web.xml
index.tml
3.源文件
1)Index.java
package demo.pages;
import java.util.Date;
public class Index
{
public Date getCurrentTime()
{
return new Date();
}
}
2)index.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<head>
<title>tutorial1 Start Page</title>
</head>
<body>
<h1>tutorial1 Start Page</h1>
<p> This is the start page for this application, a good place to start your modifications.
Just to prove this is live: </p>
<p> The current time is: ${currentTime}. </p>
<p>
[<t:pagelink t:page="Index">refresh</t:pagelink>]
</p>
</body>
</html>
3) web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>app Tapestry 5 Application</display-name>
<context-param>
<!-- The only significant configuration for Tapestry 5, this informs Tapestry
of where to look for pages, components and mixins. -->
<param-name>tapestry.app-package</param-name>
<param-value>demo</param-value>
</context-param>
<context-param>
<param-name>tapestry.production-mode</param-name>
<param-value>false</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>
</filter-mapping>
</web-app>
4.所需要的lib库