免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1205 | 回复: 0
打印 上一主题 下一主题

Tiles in Spring [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-21 21:17 |只看该作者 |倒序浏览

14.3. Tiles
It is possible to integrate Tiles - just as any other view technology - in web applications using Spring. The following describes in a broad way how to do this.
NOTE: This section focuses on Spring's support for Tiles 2 (the standalone version of Tiles, requiring Java 5+) in the org.springframework.web.servlet.view.tiles2 package. Spring also continues to support Tiles 1.x (a.k.a. "Struts Tiles", as shipped with Struts 1.1+; compatible with Java 1.4) in the original org.springframework.web.servlet.view.tiles package.
14.3.1. Dependencies
To be able to use Tiles you have to have a couple of additional dependencies included in your project. The following is the list of dependencies you need.

  • Tiles version 2.0.4 or higher

  • Commons BeanUtils

  • Commons Digester

  • Commons Logging

    These dependencies are all available in the Spring distribution.
    14.3.2. How to integrate Tiles
    To be able to use Tiles, you have to configure it using files containing definitions (for basic information on definitions and other Tiles concepts, please have a look at
    http://tiles.apache.org
    ). In Spring this is done using the TilesConfigurer. Have a look at the following piece of example ApplicationContext configuration:
      
       
          /WEB-INF/defs/general.xml
          /WEB-INF/defs/widgets.xml
          /WEB-INF/defs/administrator.xml
          /WEB-INF/defs/customer.xml
          /WEB-INF/defs/templates.xml
       
      
    As you can see, there are five files containing definitions, which are all located in the 'WEB-INF/defs' directory. At initialization of the WebApplicationContext, the files will be loaded and the definitions factory will be initialized. After that has been done, the Tiles includes in the definition files can be used as views within your Spring web application. To be able to use the views you have to have a ViewResolver just as with any other view technology used with Spring. Below you can find two possibilities, the UrlBasedViewResolver and the ResourceBundleViewResolver.
    14.3.2.1. UrlBasedViewResolver
    The UrlBasedViewResolver instantiates the given viewClass for each view it has to resolve.
      
    14.3.2.2. ResourceBundleViewResolver
    The ResourceBundleViewResolver has to be provided with a property file containing viewnames and viewclasses the resolver can use:
      
    ...
    welcomeView.class=org.springframework.web.servlet.view.tiles2.TilesView
    welcomeView.url=welcome (this is the name of a Tiles definition)
    vetsView.class=org.springframework.web.servlet.view.tiles2.TilesView
    vetsView.url=vetsView (again, this is the name of a Tiles definition)
    findOwnersForm.class=org.springframework.web.servlet.view.JstlView
    findOwnersForm.url=/WEB-INF/jsp/findOwners.jsp
    ...
    As you can see, when using the ResourceBundleViewResolver, you can easily mix different view technologies.
    Note that the TilesView class for Tiles 2 supports JSTL (the JSP Standard Tag Library) out of the box, whereas there is a separate TilesJstlView subclass in the Tiles 1.x support.
    14.3.2.3. SimpleSpringPreparerFactory and SpringBeanPreparerFactory
    As an advanced feature, Spring also supports two special Tiles 2 PreparerFactory implementations. Check out the Tiles documentation for details on how to use ViewPreparer references in your Tiles definition files.
    Specify SimpleSpringPreparerFactory to autowire ViewPreparer instances based on specified preparer classes, applying Spring's container callbacks as well as applying configured Spring BeanPostProcessors. If Spring's context-wide annotation-config has been activated, annotations in ViewPreparer classes will be automatically detected and applied. Note that this expects preparer classes in the Tiles definition files, just like the default PreparerFactory does.
    Specify SpringBeanPreparerFactory to operate on specified preparer names instead of classes, obtaining the corresponding Spring bean from the DispatcherServlet's application context. The full bean creation process will be in the control of the Spring application context in this case, allowing for the use of explicit dependency injection configuration, scoped beans etc. Note that you need to define one Spring bean definition per preparer name (as used in your Tiles definitions).
      
       
          /WEB-INF/defs/general.xml
          /WEB-INF/defs/widgets.xml
          /WEB-INF/defs/administrator.xml
          /WEB-INF/defs/customer.xml
          /WEB-INF/defs/templates.xml
       
      
      
      


    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/37262/showart_571940.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP