15.5.1.4. Dependency Injecting Spring Beans into Tapestry pages - Tapestry 4.0+ style
Effecting the dependency injection of Spring-managed beans into Tapestry pages in Tapestry version 4.0+ is so much simpler. All that is needed is a single add-on library, and some (small) amount of (essentially boilerplate) configuration. Simply package and deploy this library with the (any of the) other libraries required by your web application (typially in WEB-INF/lib).
You will then need to create and expose the Spring container using the method detailed previously. You can then inject Spring-managed beans into Tapestry very easily; if we are using Java5, consider the Login page from above: we simply need to annotate the appropriate getter methods in order to dependency inject the Spring-managed userService and authenticationService objects (lots of the class definition has been elided for clarity)...
package com.whatever.web.xportal.pages;
public abstract class Login extends BasePage implements ErrorProperty, PageRenderListener {
@InjectObject("spring:userService")
public abstract UserService getUserService();
@InjectObject("spring:authenticationService")
public abstract AuthenticationService getAuthenticationService();
}
We are almost done... all that remains is the HiveMind configuration that exposes the Spring container stored in the ServletContext as a HiveMind service; for example:
<!---->
<module id="com.javaforge.tapestry.spring" version="0.1.1"></module>
<service-point id="SpringApplicationInitializer" interface="org.apache.tapestry.services.ApplicationInitializer" visibility="private"></service-point>
<invoke-factory></invoke-factory>
<construct class="com.javaforge.tapestry.spring.SpringApplicationInitializer"></construct>
<set-object value="service:hivemind.lib.DefaultSpringBeanFactoryHolder" property="beanFactoryHolder"></set-object>
<!---->
<contribution configuration-id="tapestry.init.ApplicationInitializers"></contribution>
<command id="spring-context" object="service:SpringApplicationInitializer"></command>
If you are using Java5 (and thus have access to annotations), then that really is it.
If you are not using Java5, then one obviously doesn't annotate one's Tapestry page classes with annotations; instead, one simply uses good old fashioned XML to declare the dependency injection; for example, inside the .page or .jwc file for the Login page (or component):
<inject property="userService" object="spring:userService"></inject>
<inject property="authenticationService" object="spring:authenticationService"></inject>
In this example, we've managed to allow service beans defined in a Spring container to be provided to the Tapestry page in a declarative fashion. The page class does not know where the service implementations are coming from, and in fact it is easy to slip in another implementation, for example, during testing. This inversion of control is one of the prime goals and benefits of the Spring Framework, and we have managed to extend it all the way up the J2EE stack in this Tapestry application.
分享到:
相关推荐
Tapestry是一个基于控件的框架以致于用它开发Web应用类似开发传统的GUI应用。你用Tapestry开发Web应用时你无需关注以操作为中心的(Operation-centric) Servlet API.引用Tapestry网站上的一句话:"Tapestry用对象...
Tapestry + spring Tapestry + spring
一个TSH(tapestry+Hibernate+Spring)配置例子
tapestry5.3.3+spring+hibernate整合源码,也可以到官方网站下载:http://flywind.org/newtechnologydetail/135
强大的tapestry框架的学习入门资料,详细介绍了tapestry的常用开发文档。
这是Tapestry5.3.8 版本的一个大Demo,集合Spring4.0, 采用Maven 项目管理工具,没有集合Hibernate。 之所以说是个大Demo,是因为这项目中包含的内容并不少,包含: 1)解决了Tapestry5.3.8中文Bug问题 2)Tapestry...
tapestry 集成 spring ppt文档及可运行的代码
该包包含: Tapestry5最新中文教程.doc tapestry.pdf tapestry开发流程.docx Tapestry开发指南0.8.pdf tapestry用户手册.pdf
从多方面来讲解 Tapestry应用,比如应用的页面导航(page navigation)、依赖性(dependency)和资源注入(resource injection)、用户输入验证(input validation)和应用状态管理(state management)。...
是一本由多本Tapestry资料整合而成。包括一些Tapestry的实例。
Tapestry~需要学习资料的进来看看 纯英文原版
Tapestry 4 官方文档中文版本,现在中文资料比较少,和大家共享一下
16.5 Spring中带有DWR的支持Ajax的应用程序 16.5.1 直接Web远程控制 16.5.2 访问Spring管理的Bean DWR 16.6 小结 附录A 装配Spring A.1 下载Spring A.1.1 研究Spring发布 A.1.2 构建自己的类路径 A.2 把...
16.5 Spring中带有DWR的支持Ajax的应用程序 16.5.1 直接Web远程控制 16.5.2 访问Spring管理的Bean DWR 16.6 小结 附录A 装配Spring A.1 下载Spring A.1.1 研究Spring发布 A.1.2 构建自己的类路径 A.2 把...
在维普上下载下来的。介绍3个框架的整合!!!!!!
tapestry-spring-5.2.6.jar,java spring框架依赖,可以直接使用
Tapestry 4 官方文档中文版本,包括Tapestry4 Quick Start(2)和Tapestry4 Users Guide(2)两个文档 还有tapestry中文字典等
自己熬夜敲出来的 t5 增删改查的demo 写的也很规范 对初学者很有帮助。
16.5spring中带有dwr的支持ajax的应用程序 16.5.1直接web远程控制 16.5.2访问spring管理的beandwr 16.6小结 附录a装配spring a.1下载spring a.1.1研究spring发布 a.1.2构建自己的类路径 a.2把spring添加为一...
Tapestry5.1+Spring2.5.6+Hibernate3.2.5写得简单CURD的程序,借鉴了SpringSide3.1.4.2的配置及数据层。实现了添加,列表,修改,删除,显示等操作。内有源码及生成的WAR文件。可以直接使用!