Home Java javaTutorial Using Tiles framework in Struts

Using Tiles framework in Struts

Dec 17, 2016 am 10:50 AM


 This is the third part of the series on using the Tiles framework in the book Jakarta Struts Programming. It mainly explains how to use the tag library (including: insert, definition, put, putList, add, get, getAsString, useAttribute, importAttribute, and initComponentDefinitions) .
 
 The Tiles Tag Library
 This section introduces the jsp custom tags used by the Tiles framework. Table 14-1 lists the tags available for the framework. These tags are very similar to those provided by other template-based frameworks, but the Tiles framework contains richer functionality.
 
 Table 14-1: Tags in the Tiles framework tag library
  
  Tag name                                                    wealthdie
    Add an element to the environment list.
 Definition  Create a Tiles component definition.
 Get  Gets the content (content) from the request scope. This content is placed by the put tag
  .
 GetAsString Pass the value specified by the tile/component/template attribute to the current
 JspWriter.
 ImportAttributeIntroduces a Tiles attribute into the specified context;
 initComponentDefinitions Initializes a Tiles definition factory.
 Insert  Insert a Tiles component.
 Put   Set a property to a Tiles context.
 PutList   Declares a list that is passed as a property.
 useAttribute  Use an attribute value in the page.
 
 insert tag
 insert tag is responsible for inserting content into the page. In a Tiles layout, the insert tag uses the content specified by the attribute value. In non-Tile layouts, the insert tag is used to obtain a frame (layout) and the put tag is used to pass the content to the layout.
 Table 14-2 lists the attributes of the insert tag:
 
 Table 14-2: Attributes of the insert tag
 
 Attribute name (Attribute name)  Description
 Attribute   The attribute name of the current Tiles/component context, this attribute value is Passed by the name attribute.
 beanName The name of the Bean is used as a value. The Bean is obtained from the specified content.
 The Bean can be obtained from the specified context, if any. Otherwise, you have to use the pageContext.findAttribute() method to obtain it. If the beanPRoperty attribute has been specified, this value can also be obtained from the corresponding Bean attribute.
 If this Bean (or Bean's attribute value) is an instance of a certain attribute class (Direct, Instance, etc.), then the insertion process depends on the type of the class. In addition, the toString() method of the Bean is called, and the return value is String and passed to the name attribute.
 beanProperty The name of the Bean property (property), if specified, then this value is obtained from the
 Bean's property (property).
 beanScope The scope of the Bean, if not specified, the pageContext.findAttribute() method can be used. The scope of a bean can be any JSP, component, or template. In the latter two cases (component, template), the bean can be in the Tiles (tile)/component/template content
 component  A string describing the tile or template (template) URI. Template (template), Page and component properties must have exactly the same behavior
controllerUrl The direct URI of the controller before the page was inserted. This URI is usually used to indicate a strUCt action. This controller (action) is used to prepare data for the inserted tile. There can only be one controllerUrl or controllerClass
 controllerClass is a type of control class that is called directly before the page is inserted. This class is used to prepare data for inserted tiles. There can be only one controllerUrl or controllerClass. This class implements or extends one of the following classes: org.apache.struts.tiles.Controller, org.apache.struts.tiles.ControllerSupport, or org.apache.struts.action.Action.
  Definition   Insert the name of the definition. Definitions are defined in a centralized file. Now, only a factory definition can be inserted using this attribute. Insert a definition defined with definition, use beanName="".
  flush   true or false. If true, the current page will output the stream before tile insertion.
  ignore   If this attribute is set to true and the attribute specified by name does not exist , will simply return a result with nothing written. The initial value is set to false, which can throw a runtime exception. Name is the name of the entity to be inserted. The search is in the following order: definition, attribute, then page.
 page  A URI string representing the tile or template. Template, page, and component attributes must strictly have the same behavior
role If the user is in the specified role, then this tag will take effect. Otherwise, this tag will be ignored and no content will be written.
 template  A URI string representing a tile or template. The template, page, and component attributes must have strictly the same behavior
 
 definition tag
 The definition tag uses the bean definition method to create a tile (template). This newly created bean is identified by an id in the requested scope. Some of the syntax of the definition tag is the same as that of insert. New definitions can extend definitions already described in the definition factory (xml file) and can override previously defined parameters.
 
 Table 14-3 lists the attributes supported by the definition tag
 
 Attribute name Description
  extends can be used to extend the parent definition. This parent definition is defined in the definitions factory.
 id defines the name of the bean, this attribute is required
 page URL to insert template/component. Same as template.
 role Before inserting a definition, check the role. If the current user does not define this role, then this definition will not be inserted. Check when inserting, not when defining.
 Scope is created when a bean is newly defined. If not specified, the default value is the page scope.
  The URL of template tile/component/template (a JSP page) .
 The following snippet shows how to use the definition tag in JSP.
 
   id="storefront.default"
 page="/layouts/storefrontDefaultLayout.jsp"
 scope="request">
  
 
 
 
 
  A complete example will be shown in "Declaring Definitions in a JSP Page" later in this chapter
  
 put tag
  The put tag is used to pass attributes to a tile components. This tag can only be used inside an insert or definition tag. The value of the put tag is specified by the value attribute or tag body. Value types are also often specified.
  string: As the name suggests
Page or template: The content contains the specified URL. The name is usually used as the URL.
  definition: The content is obtained from the definition of the specified (from factory). The name is used as the defined name. If type is used, it will be inserted into the tile by the get or insert tag. If the type attribute is not specified, the content is untyped unless it comes from a typed bean.
  Tip: Setting direct="true" and setting type="string" is the same.
  
 Table 14-4 lists the attributes of the put tag.
 
 Property Name  Description
 beanName  The name of the Bean is used in the same way as the value. The Bean is obtained from the extraordinary content. If there is one, you can also use the pageContext.findAttribute() method to obtain it. If the beanProperty attribute has been specified, this value can be obtained from the corresponding Bean property.
 beanProperty The name of the Bean property (property), if specified, then this value is obtained from the Bean's property (property).
 beanScope  The scope of the Bean, if not specified, the pageContext.findAttribute() method can be used. The scope of a bean can be any JSP, component, or template. In the latter two cases (component, template), the bean can be in the Tiles (tile)/component/template content
 content  Content is within the tile scope. The attribute is equivalent to the value attribute and is added for compatibility with JSP template tags. .
Direct Content control method: true means that the content is displayed directly; false means that the content is included. false is the default value. It is also a way to specify the content type. If direct="true", content is "string"; if direct="false", content is "page". This attribute is added for compatibility with JSP template tags. .
Name
 Type  The type of content. Valid values ​​are "string", "page", "template", or "definition". The value of the property can be String or Object. The value is assigned directly. (value="avalue") or obtained from a bean. A value, content, or beanName must exist.
 putList tag
The putList tag creates a list and passes it by value in the tile. List elements are added using the add tag. This tag can only be used in insert or definition tags.
 
 Table 14-5 lists the attributes of the putList tag.
 
 Attribute name Description
 The name of the Name List. This attribute is required.
 
 add tag
 The add tag adds an element to the surrounding list. This tag can only be used in the putList tag. This value can be assigned directly. (value="avalue") or obtained from a bean. A value or beanName must be specified.
 
 Table 14-6 lists the attributes of the add tag.
 
 Attribute Name   Description
 beanName   The name of the Bean is used in the same way as the value. The Bean is obtained from the extraordinary content. If so, you can also use pageContext.find

The above is the content of using the Tiles framework in Struts. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

In-depth discussion of the principles and practices of the Struts framework In-depth discussion of the principles and practices of the Struts framework Feb 18, 2024 pm 06:10 PM

Principle analysis and practical exploration of the Struts framework. As a commonly used MVC framework in JavaWeb development, the Struts framework has good design patterns and scalability and is widely used in enterprise-level application development. This article will analyze the principles of the Struts framework and explore it with actual code examples to help readers better understand and apply the framework. 1. Analysis of the principles of the Struts framework 1. MVC architecture The Struts framework is based on MVC (Model-View-Con

Analyze the working principle of Struts2 framework Analyze the working principle of Struts2 framework Jan 05, 2024 am 08:29 AM

Exploring the internal mechanism of the Struts2 framework Struts2 is a popular JavaWeb application framework that is widely used to develop Web applications based on the MVC architecture. It has made a lot of improvements and optimizations based on Struts1, providing more powerful and flexible functions. Before we delve into the inner workings of the Struts2 framework, we need to understand some basic concepts. The core of the Struts2 framework is MVC (Model-View-Controlle

Java backend development: API MVC framework development using Java Apache Struts Java backend development: API MVC framework development using Java Apache Struts Jun 17, 2023 am 10:03 AM

With the popularity of the Internet and smart mobile devices, the development of web applications has become increasingly important. As an excellent cross-platform programming language, Java is favored by developers. In Java back-end development, using the MVC framework can help us improve development efficiency and reduce development costs. This article will introduce the MVC framework development of API using JavaApacheStruts. 1. MVC framework MVC (Model-View-Contro

What are the principles and applications of the struts framework? What are the principles and applications of the struts framework? Jan 03, 2024 pm 05:31 PM

The principle of the struts framework: By using Java Servlet/JSP technology, an application framework based on the MVC design pattern of Java EE Web applications is implemented. It uses one or more Action classes to process user requests and return the results to the user. Application of struts framework: 1. Build Web applications; 2. Process form data; 3. Integrate third-party libraries; 4. Implement internationalization; 5. Build RESTful API.

Introduction to Struts framework in Java language Introduction to Struts framework in Java language Jun 10, 2023 pm 08:00 PM

Introduction to the Struts Framework in Java Language With the gradual popularity of Web applications, such as Web websites and enterprise application systems, the JavaEE (Enterprise Edition) architecture has gradually become a mainstream choice. In the JavaEE architecture, due to the popularity of the MVC (Model-View-Controller) design pattern, the Struts framework has become one of the commonly used web application frameworks. In this article, we’ll take a closer look at

In-depth analysis of the operating mechanism of the Struts2 framework In-depth analysis of the operating mechanism of the Struts2 framework Jan 05, 2024 pm 03:36 PM

In-depth analysis of the working principle of the Struts2 framework Struts2 is an excellent Java Web application development framework. It provides a development method based on the MVC (Model-View-Controller) pattern to help developers build and maintain Web applications more quickly. Understanding the working principle of the Struts2 framework is very important for developers. This article will help readers gain an in-depth understanding of the working principle of the Struts2 framework through detailed analysis and specific code examples.

Detailed analysis of the implementation principle of Struts2 framework Detailed analysis of the implementation principle of Struts2 framework Feb 21, 2024 pm 05:54 PM

Detailed analysis of the implementation principle of the Struts2 framework. As a widely used JavaWeb application framework, the Struts2 framework's excellent design and performance make it a favorite tool for developers. Understanding the implementation principles of the Struts2 framework is of great significance to improving developers' understanding and application level of the framework. This article will analyze the implementation principles of the Struts2 framework in detail and provide specific code examples to help readers gain a deeper understanding of this framework. 1. Brief introduction of Struts2 framework

Explore the principles and applications of struts framework Explore the principles and applications of struts framework Jan 04, 2024 am 08:19 AM

In-depth analysis of the principles and applications of the Struts framework Summary: The Struts framework is an excellent JavaWeb application development framework. It is based on the MVC design pattern and a series of tag libraries and interceptors, providing developers with a simple and standardized way. to build web applications. This article will provide an in-depth analysis of the principles and applications of the Struts framework, including the framework's working principle, main components, and sample code to demonstrate its specific applications. 1. Working principle of Struts framework Struts

See all articles