这里有一个Home页的屏幕抓图,下面跟着它的页面模板
贴子相关图片:

<html>
<head>
<title>Welcome to the Tapestry Login Application</title>
</head>
![]()
<body>
<h1>Welcome to the Tapestry Login Application</h1>
<span jwcid="@PageLink"① page="Login">Login</span>
</body>
</html>
这个Home页的页面模板除了一个jwcid属性定义使用一个Tapestry PageLink①控件以外都是标准的HTML。
PageLink控件生成了一个指向Login页的超链接。既然Home页没有任何动态的行为所以它不需要页面规范和页面对应的Java类。
这里是Login页的屏幕抓图,后面跟着是它的页面模板。
Login.html
<html>
<head>
<title>
<span key="title">①Login</span>
</title>
</head>
![]()
<body jwcid="@Body">②
<span jwcid="@Conditional" condition="ognl:beans.delegate.hasErrors">③
<div style="color: red">
<span jwcid="@Delegator" delegate="ognl:beans.delegate.firstError">④
Error Message
</span>
</div>
</span>
<p style="font-weight: bold" >
<span key="hint">Hint: Your password is your username spelled backwards.</span>
</p>
![]()
<form jwcid="@Form" listener="ognl:listeners.login" delegate="ognl:beans.delegate">
![]()
⑤
<table>
<tr>
<td align="right">
<span jwcid="@FieldLabel" field="ognl:components.inputUsername"⑥>
Username:
</span>
</td>
<td>
<input type="text" jwcid="inputUsername"⑦ value="simpson_h"
![]()
size="30"/>
</td>
</tr>
![]()
<tr>
<td align="right">
<span jwcid="@FieldLabel" field="ognl:components.inputPassword">
Password:
</span>
</td>
<td>
<input type="text" jwcid="inputPassword" hidden="true" value=""
![]()
size="30"/>
</td>
</tr>
![]()
<tr>
<td colspan="2" align="center">
<input type="submit" jwcid="@Submit" value="message:login"/>
</td>
</tr>
</table>
</form>
</body>
</html>
![]()
这个页面模板大多数是通常的HTML。我们从页面模板中可以看到Tapestry的区域化特性:它使用一个span元素,这个span元素带有一个叫key的属性,key的值映射到Login.properties文件里一个属性。一个Body控件被声明使用,因为它对客户端的javascript校验是必需的。
为Form component⑤设定delegate属性激活表单输入验证。delegate属性是我们在页面规范里声明的org.apache.tapestry.valid.IvalidationDelegate的实现类。如果验证错误发生了,我们用Conditional component③控件判断delegate是否有任何错误,如果有就把第一个错误④显示给用户。如果ognl 表达式ognl:beans.delegate.hasErrors 为true,Conditional控件将显示它的内容实体。所有的页面类和控件类都从AbstractComponent继承来一个叫beans的属性。这个beans属性是一个org.apache.tapestry.IbeanProvider的实例,利用它可以通过名字取得在页面规范文件里定义的beans.FieldLabel⑥被用于为inputuserName validField控件显示标签,这个FieldLabel控件也被用来与表单的验证代理协作,指出包含错误的输入域。
InputUserName⑦控件是一个显示控件的例子。显式控件是指在页面规范文件声明的控件。InputUsername和inputPassword控件都是显式的,它们与FieldLabel联合显示它们的displayName属性。
下面的是Login页的资源文件。Login.properties跟页面规范一并存放在WEB-INF目录。
Login.properties
title = Login to the Application
hint = Hint: Your password is your username spelled backwards.
login = Login
username = Username:
password = Password:
invalidpassword = Invalid Password
![]()
Here is the page specification for the Login page.
Login.page
<?xml version="1.0"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd>
![]()
<page-specification class="com.ociweb.tapestry.Login">
<bean name="delegate" class="org.apache.tapestry.valid.ValidationDelegate"/>①
![]()
<bean name="requiredValidator"②
class="org.apache.tapestry.valid.StringValidator">
<set-property name="required" expression="true"/>
