Home >Java >javaTutorial >Using Tiles framework in Struts

Using Tiles framework in Struts

黄舟
黄舟Original
2016-12-17 10:50:191230browse


 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:
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