Struts is developed with tiles

Source: Internet
Author: User
Tiles is excellent in page layout management and reusable, which makes our ideas very smooth during the development process, especially in the struts development project process, if tiels is used to assist development, it can often get twice the result with half the effort.

For more information about tiles, visit

Http://www.lifl.fr /~ Dumoulin/tiles/

Here I want to talk about my experience in terms of usage:

In a project, most pages have the same layout. If we classify pages of the same style into one category, there will be no more categories. (The classification of different projects varies depending on whether the page style planning is efficient)

Suppose we propose a type of page (such as product management) style with the following layout:
 
Then we can define such a general type in the tiles-defs.xml as follows:

Tiles-defs.xml put under/yourwebapp/WEB-INF/

  1. <? XML version = "1.0" encoding = "ISO-8859-1"?>
  2. <! Doctype tiles-Definitions public
  3. "-// Apache Software Foundation // DTD tiles configuration 1.1 // en"
  4. Http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd>
  5. <Tiles-Definitions>
  6. <! -Layout type 1 -->
  7. <Definition name = "mainlayout" Path = "/Homepage. jsp">
  8. <Put name = "TOP" value = "/header. jsp"/>
  9. <Put name = "menu" value = "/menu. jsp"/>
  10. <Put name = "Main" value = "/Main. jsp"/>
  11. <Put name = "footer" value = "/footer. jsp"/>
  12. </Definition>
  13. ......
  14. <! -Layout type 2 -->
  15. <Definition>
  16. ......
  17. </Definition>
  18. ......
  19. </Tiles-Definitions>

The above defines a layout type. Assume that the layout is named a layout. Next we will list two layout methods for pages of this type to add product pages. In the end, we will consider addproducts. JSP page, but how do we use the layout style of a layout?

As follows:

...... Connect tiles-defs.xml ......

  1. <! -Layout type A Layout 1 -->
  2. <Definition name = "mainlayout" Path = "/Homepage. jsp">
  3. <Put name = "TOP" value = "/header. jsp"/>
  4. <Put name = "menu" value = "/menu. jsp"/>
  5. <Put name = "Main" value = "/Main. jsp"/>
  6. <Put name = "footer" value = "/footer. jsp"/>
  7. </Definition>
  8.  
  9. <! -Layout type A layout "subclass 1: add product" 1 -->
  10. <Definition name = "mainlayout_products_add"Extends= "Mainlayout">
  11. <Put name = "Main" value = "/addproducts. jsp"/>
  12. <! -It is equivalent to replacing the main content in layout A with what we need and retaining others -->
  13. </Definition>
  14. <! -Layout type A layout "subclass 2: querying products" 1 -->
  15. <Definition name = "mainlayout_products_search"Extends= "Mainlayout">
  16. <Put name = "Main" value = "/searchproducts. jsp"/>
  17. <! -It is equivalent to replacing the main content in layout A with what we need and retaining others -->
  18. </Definition>
  19. ......
  20. ......

The preceding section only describes the layout type. Other layout types (such as layout B and layout c .....) There is no difficulty in using the same method for expansion.

The following is a brief description of some tiles configuration in the struts-config.xml, in struts1.1 tiles is to use struts extension mechanism to complete the load, the code is very simple as follows:

  1. // Struts-config.xml
  2. ......
  3. <Plug-in classname = "org. Apache. Struts. Tiles. tilesplugin">
  4. <Set-Property = "definitions-config"
  5. Value = "/WEB-INF/tiles-defs.xml"/>
  6. </Plug-in>

If you have multiple tiles configuration files, separate them with commas.
The following is a description of action mapping after tiles.

For example, if you want to add a product, you must first load the product type on the add page:

Addproductaction. Do --> productaction --> addproducts. jsp
Productaction: return the client end to complete the collection of item types

  1. // Struts-config.xml
  2. ............
  3. <Action Path = "/addproductaction"
  4. Type = "com. ***. productaction">
  5. <! -After the result is successful, return layout a subclass 1 -->
  6. <Forward name = "Path =" mainlayout_products_add ">
  7. </Action>
  8. ............

All right, the above is a brief description of the operation process using tiles. For more information about tiles, see the connection provided above.

The struts release package also contains tilse documents and examples.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.