Introduction to Tiles Tags in Struts

zhaozj2021-02-16  50

Introduction to TILES

I found these details about Tiles documents, the introduction between this Struts documentation is the best for beginners (individual thinking), so translates it, for what to understand this You don't want to see the E text, you can refer to it. The translation of the vulnerability is inevitable, I hope everyone will look at the original text, I hope everyone will help me correct, thank you.

1 Introduction

The TILES framework allows us to set up a web page. For example, the page in the figure below is built by combining a Header, a FOOTER, a Menu and a body.

Every Tiles (Header, Menu, Body, ...) is a JSP page, which can also be built by combining other Tiles.

Applying Tiles is a way to apply Java: You need to define Tiles (Methods), then you can "call" the method body in any where you need, and pass some parameters. In Tiles, in order to avoid confusion with the request parameter, parameters is called attributes.

Tiles Method (also known as content - Translator Note) can be a simple JSP page, or a strut, an action, or any URI pointing to existing web resources.

Insert or call Tiles to complete: by placing anyworthy in JSP. Insert can also be done by the following method: specify a custom name as the path to the Struts Forward; or specify a custom name for the INPUT, Forward, or Include property as the Struts Action.

Tiles method is used to create a layout, a reusable part, etc., while Tiles's insertion operation is used to insert Tiles. The same TILES can be reused multiple times at the same site or even the same page.

Tiles Insert can be linked to a logical name called "definition" in tiles. A Tiles definition contains a logical name, a main page, and some attribute values. The deciation of the definition is not inserted into the TILES method body associated with it, it just let Tiles associate with its logical name. You can use the logical name that can be used in the Tiles place, so that the corresponding tiles and its properties are inserted.

The definition of Tiles definition can be performed in the JSP page or in one or more center control files. Definition can inherit the definition of another Tiles, overload some properties, add some new properties, and more. This allows the "parent class" definition to define some universal layout, header, menu, footer. All other definition inherited to the parent class can simply change its definition to change the entire page.

2. Simple example

(1) Insert into the JSP page:

This example inserts the page specified in the tag into the entire page. The Page property can be a URL that pointing to any existing network resource.

(2) Insert a TILES simultaneously passes the attribute value:

This example inserts the specified page and passes its attribute value. The attribute value is stored in the Context of Tiles, which is also passed to the inserted tag and can then be accessed by their name.

(3) Get an attribute as a String

This example gave the value of the "Tilte" property and print it as a string in the current output stream. The toString () method is applied to this attribute value, allowing as a value to pass any object.

(4) Insert Tiles by reference properties

This example is inserted into Tiles referenced by the "MENU" attribute value. The current Tiles CONTEXT first gets this attribute value, then it is used to be used as a page target.

(5) Typical page layout

This example is a typical header-footer-menu-body combination page layout.

This layout can be declared in a JSP page (such as: /Layouts/classicLayout.jsp). It can be used together with the TAG described in Example (2).

3.Tiles Definition The definition contains a logical name and some attribute values ​​with Tiles URL. Definitions are not inserted into tiles. Insert is completed in the name of the definition. A Definition logical name can be used multiple times in the site, and the easy multiplexing of Tiles is implemented.

Tiles Definition can inherit from another definition and overload its properties or add attributes. This makes it easier to construct different definition through some properties. For example, you can define a "parent class" definition simultaneously defines the primary header, menu, footer, and a default Title. Then let the definitions of each page inherit from this "parent class" definition and overload the Title and Body properties.

The definition of Tiles definitions can be performed in the JSP page or in one or more center control files. In order to enable the definitions defined in the central control file, you need to initialize the Definitions Factory, which can explain Definitions in the file and provide them to the Tiles framework.

4. Make the definition pool

In order to take the Tiles definitions defined in the file, you need to write these files and initialize the definition pool.

Initialization varies depending on whether you apply Struts or the Struts version used (here only the configuration of the Struts1.1 version) is introduced.

Struts1.1

Plug-in is used to make Tiles Definition take effect. The plugin creates a definition pool and passes it to a configuration object with parameters. The parameters can be configured in the web.xml file or as the parameters of the plugin. The plugin first reads parameters from Web.xml, then overloads the parameters that are also configured in the plugin. All parameters are optional or ignore them. The plugin should be declared in each struts-config.xml file:

Value = "/ Web-inf / tiles-defs.xml,

/Web-inf/tiles-tests-defs.xml ,/web-inf/tiles-tutorial-defs.xml,

/Web-inf/tiles-examples-defs.xml "/>

l Definitions-config: (optional)

Specify the name of the configuration file. There can be multiple file names, between commas.

l Definitions-Parser-Validate: (optional)

Specifies whether the XML interpreter verifies Tiles configuration files.

TRUE :: Verification. DTD should be specified at the beginning of the file (default)

FALSE: Do not verify.

l ModuleaWare: (Optional) Specifies whether tiles defines whether the pool is the module. If you are true (default), there is a definition pool corresponding to each Struts module. If it is false, there will be a definition pool for all modules. Corresponding to the latter, there is still a need for each module to define a plug-in plugin. Define the pool will initialize the definition pool in the first PLUG-IN plugin (generally in the plugin associated with the default module).

TRUE: TILES framework is a module.

False: Tiles Framework has only one shared pool (default) in all modules.

l tilesutilimplclassname: (Option - Advanced User)

Specifies the class name of the TILESUTIL used. The specified class should be a subclass of the TileSutilStrutsImpl class. This will make the moduleaWare option failed.

Specifies "TilesUtilStrutsImpl" equivalent to moduleaware = false.

Specifies "TilesutilStrutsModuleImpl" equivalent to moduleaware = true.

When this is encountered for the first time, it is executed and is only executed once. To avoid problems, it is recommended to use the same value in all TileSplugin statements.

The TILESPLUGIN class creates a defined pool for each Struts module.

If ModuleaWare is in the False state, create a shared definition pool for all modules. For the latter, define the pool will initialize the parameters found in the first plugin. In each module, the corresponding PLUGIN should be declared, and the moduleaWare should be in the same state throughout the application.

The path in Tiles is relative to main context.

You don't have to specify the specific TileSremeRequestProcessor, Plug-in will process it, however, you want to specify your own requestProcessor, then it should inherit from TileSremeStProcessor. PLUG-I will check this constraint.

5. Define the syntax of the file

The syntax of the definition file can be found in the Tiles-Config_1_1.dtd file.

Here is a simple example:

DOCTYPE TILES-Definitions PUBLIC

"- // Apache Software Foundation // DTD TILES Configuration // En"

"http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">

IT overloads the page title and the body buy.use the Same Mechanism to Defe New Pages Sharing Common

Properties (Here Header, Menu, Footer, Layout)

->

6. Debugging

If you want to debug a page built by Tiles, you can follow the suggestions below:

l Independent checking each tiles. Access to those nested Tiles to test whether they are operating normally.

Yes

Tiles

For the log, please check out for details.

Commons-logging

Help file for packages.

转载请注明原文地址:https://www.9cbs.com/read-22523.html

New Post(0)