1. Home.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="org.apache.tapestry.html.BasePage"/> ==================================================== 2.Home.html ==================================================== <html> <head> <title>Login</title> </head> <body> <span jwcid="@PageLink" page="Test1">Login</span> </body>
============================================================= 3.TapestryTest1.application //***.application:*** 一定要和包名相同,否则会出错. ============================================================= <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE application PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN" "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd"> <application name="TapestryTest1" engine-class="test.MyEngine"> <description>add a description</description> <page name="Home" specification-path="Home.page"/> </application> ========================================================= 4. applicationContext.xml ========================================================= <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="helloBean" class="test.HelloBean"> <property name="helloWord"> <value>Hello!Justin!</value> </property> </bean> </beans> ========================================================= 5.web.xml ========================================================== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app> <display-name>TapestryTest1</display-name> <filter> <filter-name>redirect</filter-name> <filter-class>org.apache.tapestry.RedirectFilter</filter-class> </filter> <filter-mapping> <filter-name>redirect</filter-name> <url-pattern>/</url-pattern> </filter-mapping> <servlet> <servlet-name>TapestryTest1</servlet-name> <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>TapestryTest1</servlet-name> <url-pattern>/app</url-pattern> </servlet-mapping> </web-app> ================================================================================== 好了.我们现在来做一个测试用例.测试用例的名字为:Test1 6.Test1.html =========================================================================== <html> <head> <title>test1</title> </head> <body jwcid="@Body"> TEST1 <hr> <form jwcid="@Form" method="get" listener="ognl:listeners.clickLinked">name: <input type="text" jwcid="@TextField" value="ognl:hello.HelloWord" /> <input type="submit"/> </form> <hr/> <span jwcid="@Insert" value="ognl:hello.HelloWord">hello</span> </body> </html> ============================================================ 7.Test1.page ============================================================ <?xml version="1.0" encoding="UTF-8"?> <!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="test.Test1"> <description>Test1</description> <property-specification name="hello" type="test.HelloBean"> global.appContext.getBean("helloBean") </property-specification> </page-specification> ========================================================================== 8. HelloBean.java ========================================================================== package test; public class HelloBean { private String word = "Hello!World!"; public void setHelloWord(String word) { this.word = word; } public String getHelloWord() { return word; } } ======================================================================= 9.MyEngine.java ======================================================================= package test; import java.util.Map; import org.apache.tapestry.engine.BaseEngine; import org.apache.tapestry.request.RequestContext; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class MyEngine extends BaseEngine { protected void setupForRequest(RequestContext context) { super.setupForRequest(context); // insert ApplicationContext in global, if not there Map global = (Map) getGlobal(); ApplicationContext ac = (ApplicationContext) global.get("appContext"); if (ac == null) { ac = WebApplicationContextUtils.getWebApplicationContext( context.getServlet().getServletContext() ); global.put("appContext", ac); } } } ============================================================================ 10.Test1.java =========================================================================== package test; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.html.BasePage; import test.HelloBean; public abstract class Test1 extends BasePage { abstract public HelloBean getHello() ; public void clickLinked(IRequestCycle cycle) { HelloBean hello = getHello(); System.out.println(hello.getHelloWord()); } } ========================================================================== 11.总结 ========================================================================= 在写程序时,一定要注意大小写,不然会给你带来很好麻烦. 希望以上程序能对你有点帮助!!!

|