1 Overview
Introduction of the Struts Tiles technology used in the View section of View (front desk). Introducing TILES introduction, configuration, and development processes.
2. Struts-tiles technology profile
2.1 Conceptual Introduction
Tiles Framework is based on JSP Include technology. By dividing the display page into several "Tiles), enhances the reusability of the page, enhances the wind-maintainability of the application (website).
2.2 Main Features
l page division:
Divide the page according to the function module.
l Pagem template:
Set the template of the page in the XML file, the concept of the base class, will generate the different function pages we need by developing it.
l Build the page:
Read the Tiles configuration file at runtime, dynamically build the function page by different values, such as Menu List, such as Menu List.
3. Implementation description
3.1 Overview
Tiles Framework achieves the work to do, mainly including:
l Page public partial extraction: For example, each page has a common header section, a menu section, a copyright part, and more.
l Write Tiles-DEF profile: Define Layout, Menu, and so on.
l Write the corresponding template JSP: Build a general page with Tiles INSERT.
l Use the TILES frame as a Struts plug-in function install to the Struts application: This part of the work includes the configuration of web.xml, the setting of the Struts-Config plugin, the installation of the package, and more.
3.2 implementation process
Public part extraction:
Extract the public part from the static page of the page designer for the construction of the template.
Figure 1:
As shown in the legend, each app can analyze some common parts, such as Header, Menu, Footer. These are usually unchanged so that we may implement the dynamic generation of the page, mitigate development tasks.
TILES-DEF configuration file description
Definition definition
Depending on the proposed common part, you can build one or more reusable page templates. By the configuration in Tiles-Def.xml, it is convenient to use Tiles to dynamically generate our desired function page.
Example 1
This is an example of definition, built a page template to the legend 1:
Path Attribute: Defines the JSP file corresponding to the template, which is the implementation of the template. PUT Tags: Define the specific content to be filled in the template.
A definition, site.Menu.bar is nestled in Menu members. That is, it can be further detailed in detail the splitting of one of the contents in the template to realize the nested of the template.
Definition of Menu Definition
Example 2:
Here is a basic MENU definition.
PATH: Declare the JSP implemented.
Putlist: Declaration List for Display menus.
Item: Defines the display name and link of each menu item.
Definition inheritance
Example 3:
Using the extends attribute in this definition, that is, a definition can be inherited from another definition. You can overload some of the properties in the Parent Node Definition, and the contents of the Body display are replaced with /sys/sysoperadd.jsp.
DEFINITION NAMING RULE This time the TILES DEFINITION NAME rule:
Sino. Module Abbel. Application
For example: sino.doc.documentAppque Used Settings Query Page
Sino.doc.documentBacque Results Query page
SINO.Doc.documentDesque destruction Settings Query page
Sino.doc.documentlosque Lost Settings Query Page
installation
Tiles can be integrated into strut as a PLUG-I in Struts. Plug-in's properties can be defined in web.xml or defined in Struts-Config.xml. When the property is read, you will be read from the web.xml, and then read it from Struts-Config.xml. It is recommended to define directly in Sturts-Config.xml.
Property Description:
l Definitions-factory-class: You can define your own definition-factory, classname to set this property, which is I18n Factory.
l Definitions-config: Definition Path and File Name, the default value is /Web-inf/tileDefinitions.xml.
l Moduleaware: When there are multiple Definition profiles, set to true indicate that each file uses a different Factory instance, FALSE is public. The default is True.
l Definitions-Parser-Validate: Whether to perform a DTD check, default is true.
l Definitions-debug: Set the debug level, 0 lowest, 2 highest, default is 0.
All of the above properties are optional, not necessarily set.
Layout generation
Menulayout (VBOXLAYOUT.JSP):
<% @ Taglib Uri = "/ Web-inf / struts-logic.tld" prefix = "logic"%> <% @ Taglib URI = "/ Web-inf / struts-bean.tld" prefix = "bean"%> <% @ Taglib Uri = "/ Web-INF / TILES.TLD" prefix = "tiles"%> <% @ page import = "java.util.ITerator"%> <% - menu Layoutthis Layout Renders a menu with links , Each Item Is A Beanwith Following Properties: Value, Href, Icon, Tooltip. @ Param title menu
Title @ Param Items List of items. Items Are Beans -%> <% - Push Tiles Attributes in Page Context -%>
td> | | ImportAttribute: Used to introduce a good menu enumeration in the configuration file. Mainlayout implementation: Mainlayout.jsp: <% - Layout Tilesthis Layout Creates A HTML Page With Tile. @ param title string used as page Title @ Param Header Header Tile (URL of a JSP Page Or Definition Name) @Param Menu Menu Tile @ param body body Tile @ param footer footer tile -%> <% @ page contenttype = "text / html; charset = GBK"%> <% @ Taglib URI = "/ Web-inf / struts-tiles.tld" prefix = "tiles" %> |
---|