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/
- <? XML version = "1.0" encoding = "ISO-8859-1"?>
- <! Doctype tiles-Definitions public
- "-// Apache Software Foundation // DTD tiles configuration 1.1 // en"
- Http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd>
- <Tiles-Definitions>
- <! -Layout type 1 -->
- <Definition name = "mainlayout" Path = "/Homepage. jsp">
- <Put name = "TOP" value = "/header. jsp"/>
- <Put name = "menu" value = "/menu. jsp"/>
- <Put name = "Main" value = "/Main. jsp"/>
- <Put name = "footer" value = "/footer. jsp"/>
- </Definition>
- ......
- <! -Layout type 2 -->
- <Definition>
- ......
- </Definition>
- ......
- </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 ......
- <! -Layout type A Layout 1 -->
- <Definition name = "mainlayout" Path = "/Homepage. jsp">
- <Put name = "TOP" value = "/header. jsp"/>
- <Put name = "menu" value = "/menu. jsp"/>
- <Put name = "Main" value = "/Main. jsp"/>
- <Put name = "footer" value = "/footer. jsp"/>
- </Definition>
-
- <! -Layout type A layout "subclass 1: add product" 1 -->
- <Definition name = "mainlayout_products_add"Extends= "Mainlayout">
- <Put name = "Main" value = "/addproducts. jsp"/>
- <! -It is equivalent to replacing the main content in layout A with what we need and retaining others -->
- </Definition>
- <! -Layout type A layout "subclass 2: querying products" 1 -->
- <Definition name = "mainlayout_products_search"Extends= "Mainlayout">
- <Put name = "Main" value = "/searchproducts. jsp"/>
- <! -It is equivalent to replacing the main content in layout A with what we need and retaining others -->
- </Definition>
- ......
- ......
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:
- // Struts-config.xml
- ......
- <Plug-in classname = "org. Apache. Struts. Tiles. tilesplugin">
- <Set-Property = "definitions-config"
- Value = "/WEB-INF/tiles-defs.xml"/>
- </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
- // Struts-config.xml
- ............
- <Action Path = "/addproductaction"
- Type = "com. ***. productaction">
- <! -After the result is successful, return layout a subclass 1 -->
- <Forward name = "Path =" mainlayout_products_add ">
- </Action>
- ............
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.