TILES use introduction

xiaoxiao2021-03-06  48

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:

< Item value = "installation" link = "/ doc / installation.jsp" />

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

<% - iperate on items list -%> <% // add site url If link starts with "/" string link = item.getLink (); if (link.startswith ("/")) Link = Request.getContextPath () link;%>
<% = item.getValue ()%> <% // add site url if link starts with "/" string iCon = item.geticon (); if (icon.startswith ("/")) icon = request.getContextPath () icon;%>  <bean: write Name = "item" proty = "tooltip" scope = "page" ignore = "true" /> Description:

ImportAttribute: Used to introduce a good menu enumeration in the configuration file. Mainlayout implementation:

Mainlayout.jsp:

<% - Layout Tilesthis Layout Creates A HTML Page With

and tags. It rendersa header, Left menu, Body and Footer

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" %> <tiles: getAsstring name = "title" /> </ title> </ head> <body bgcolor = "# ffffff" text = "# 000000" LINK = "# 023264" alink = "# 023264" VLINK = "# 023264"> <Table Border = "0" width = "100%" cellspacing = "5"> <tr> <td colspan = "2"> <tiles: insert attribute = "header" /> <td> </ tr> <tr> <td Width = "140" Valign = "TOP"> <tiles: INSERT Attribute = 'menu' /> </ td> <td valign = "TOP" align = "left"> <tiles: insert attribute = 'body' /> </ td> </ tr> <tr> <td colspan = "2> <tiles: insert attribute =" footer "/> </ td> </ tr> </ table> </ body> </ html></p> <p>HEADER.JSP</p> <p><% @ Page ContentType = "TEXT / HTML; Charset = GBK"%> <table width = "100%" border = "0" cellspacing = "0" cellpadding = "0"> <tr> <td width = "48 % "Background =" <% = Request.getContextPath ()%> / sys / images / p012.gif "> <img src =" <= request.getcontextPath ()%> / sys / images / logo.gif "Width = "374" Height = "70"> </ td> <td width = "30%" Background = "<% = Request.getContextPath ()%> / sys / images / p012.gif"> <img src = " <% = request.getContextPath ()%> / sys / images / p001.gif "Width =" 202 "height =" 70 "> </ td> <td width =" 22% "align =" Right "Background =" <% = Request.getContextPath ()%> / sys / images / p012.gif "> <img src =" <% = request.getContextPath ()%> / sys / images / p002.gif "Width =" 203 "Height = "70"> </ td> </ tr> </ table> footer.jsp</p> <p><% @ Page ContentType = "Text / HTML; Charset = GBK"%> <table width = "100%" border = "0" cellspacing = "0" cellpadding = "0"> <TR> <TD bgcolor = "FF966B "Height =" 1 "> </ td> </ tr> <trs =" center "> <td height =" 18 "class =" font9 "> Life Insurance Life Co., Ltd. All rights reserved </ td> </ Tr> </ table></p> <p>Description:</p> <p>Title: Reads from the configuration file via the GetAsstring tag, displayed in the page.</p> <p>Header, Footer, Body, Menu: Inserte to Mainlayout.jsp by INSERT tags.</p> <p>Menulayout: Use struts: Iterate enumeration function to generate a list of Menu.</p> <p>This constitutes a page template shown in Figure 1.</p> <p>Applying Tiles (Dynamic Page) After definition, Layout has been defined, you can apply to Struts to use them instead of the URL used by Forward Mapping.</p> <p><action path = "/ tutorial / testaction2" type = "org.apache.struts.examplexample"> <forward name = "failure" path = "forward.example.failure.page" /> <Forward Name = "success" path = "forward.example.success.page" /> </ action></p> <p>The only difference regarding the Action configuration and the only difference between Tiles is that the URL used for forward mapping becomes definition definition in the definition profile.</p> <p>CONTROLLER</p> <p>For each definition, you can define a Controller. Call a Controller to do some must have some business logic before using this definition.</p> <p>l Definition settings:</p> <p><definition name = "examples.rschannel.body" Path = "/ example / tiles / rsschannels.jsp" ControllerURL = "/ example / controller / rsschannel.do"> <Putlist name = "URLS"> <add value = "</p> <p>http://www.newsforge.com/newsforge.rs"/> "ADD VALUE ="</p> <p>http://xmlhack.com/rss.php"/> ""</p> <p>http://lwn.net/headlines/rss "/> </ putlist> </ definition></p> <p>Define a ControllerURL to definition.</p> <p>l Struts Settings:</p> <p><ActionType = "org.apache.struts.webapp.tiles.rschannel.rschannel" path = "/ controller / rsschannel" /></p> <p>Configure this ControllerURL mapping Class in Struts-Config. Note that Controller Action is no Forword Mapping because it corresponds to a Tiles Definition.</p> <p>l rsschannelsaction.java:</p> <p>package org.apache.struts.webapp.tiles.rssChannel; ...... import org.apache.struts.tiles.actions *;. ...... public final class RssChannelsAction extends TilesAction {...... public ActionForward perform (ComponentContext context, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {...... List channels = (List) context.getAttribute ( "urls"); ......}} Controller org.apache.struts.tiles.actions.TilesAction class inheritance, by Reword the Perform () method to handle the necessary logic. The difference between the method and the Struts action is to more than a ComponEtContext type parameter, which can read the input properties defined in the definition through this object's GetAttribute () method.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-81210.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="81210" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.037</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'pJt2JZziKuWtHhF4voJlFWKFbIBWrOkwsykfn649eBkOSTLHD0N2tn36n3UkUJ12N9XUApRYX_2BP023sr7_2B2BGQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>