In the development of the project, we often have this experience: the same control we may use more than one, and we need to add their own style and operation of the basic style of JS code; In this case, If every place is copy Code, then, if you want to modify later, then the maintenance workload is huge, is undoubtedly a disaster. Based on this situation, we can consider using custom tags to implement code reuse and later easy maintenance.
Look at a diagram first:
is our common interface for developing custom tags, we use the quickest and easiest way to inherit the tagsupport class, just rewrite dostarttag and Doendtag method.
Production steps:
first, the preparation Java file
Code:
public class Datagridcolumntag extends tagsupport{protected string field = "";//display fields protected String searchfields = ""; /query fields add support for interval queries private string Width;private string height;private Boolean checkbox = false;//whether to display check box private Boolean sho Wpagelist = true;//defines whether the page list is displayed private Boolean Openfirstnode = false;//is not expanded first node private Boolean fit = true;//Allow table Autoscale, To fit the parent container private Boolean fitcolumns = true;//when True, the size of the auto-expand/Contract column to fit the width to prevent horizontal scrolling. Private String sortname;// Defines the column to sort private String SortOrder = "ASC";//defines the sort order of the column, which can only be "increment" or "descending". Private Boolean Showrefresh = true;// Defines whether the Refresh button is displayed private Boolean Showtext = true;//defines whether to display the Refresh button private String style = "Easyui";//List style easyui,datatablesprivate St Ring onloadsuccess;//Data Load Complete call method private string onclick;//Click event Call method private String ondblclick;//Double-click event Call method private string Querymode = "single";//Query mode private string entityname;//the corresponding entity object private string rowstyler;//Rowstyler function Private Boolean AU Toloaddata = true; Whether the list automatically loads data protected static map<string, String> Syscode = new hashmap<string, string> (), Static {Syscode.put ("Class", "Clazz");} public void setonloadsuccess (String onloadsuccess) {this.onloadsuccess = onloadsuccess;} public void Setonclick (String onClick) {this.onclick = OnClick;} public void Setondblclick (String onDblClick) {this.ondblclick = OnDblClick;} public void Setshowtext (Boolean showtext) {this.showtext = Showtext;} public void Setpagination (Boolean pagination) {this.pagination = pagination;} public void Setcheckbox (Boolean checkbox) {this.checkbox = checkbox;} public void setpagesize (int pageSize) {this.pagesize = pageSize;} public void Settreegrid (Boolean treegrid) {This.treegrid = Treegrid;} public void SetWidth (String width) {this.width = width;} public void SetHeight (String height) {this.height = height;} 。。。。。。。。。 Other set methods .... 。。。。。。。。。 public int doStartTag () throws Jsptagexception {//Empty resource urllist.clear (); Toolbarlist.clear (); Columnvaluelist.clear (); Columnstylelist.clear (); Columnlist.clear (); fields = ""; searchfiELDs = ""; return eval_page;} public int Doendtag () throws Jspexception {try {jspwriter out = This.pageContext.getOut (); if (Style.equals ("Easyui")) {OU T.print (End (). ToString ());} else {out.print (DataTables (). toString ()); Out.flush ();}} catch (IOException e) {e.printstacktrace ();} return eval_page;}}
because inheritance TagSupport so rewrite doStartTag (), Doendtag ().
Ii. Preparation of . TLD file
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE taglib Public "-//sun Microsystems, Inc.//dtd JSP Tag Library 1.2//en" "http://java.sun.com /dtd/web-jsptaglibrary_1_2.dtd "><taglib><tlib-version>1.0</tlib-version><jsp-version >1.2</jsp-version><short-name>t</short-name><uri>/easyui-tags</uri>< Display-name> "Custom Label" </display-name><tag><name>datagrid</name><tag-class> Itoo.cgform.base.tag.datagridtag</tag-class><body-content>jsp</body-content><description > Data Table </description><attribute><name>name</name><required>true</required ><rtexprvalue>true</rtexprvalue><description> List Table Label </description></attribute ><attribute><name>treegrid</name><rtexprvalue>true</rtexprvalue>< description> whether the tree list value is true or False</description></attribute><attribute><name>actionurl</name><required>true</required><rtexprvalue>true</ Rtexprvalue><description> the path of page submission </description></attribute><attribute><name> Pagination</name><rtexprvalue>true</rtexprvalue><description> whether the page is paged true,false</ description></attribute><attribute><name>title</name><rtexprvalue>true</ Rtexprvalue><description> Table title </description></attribute><attribute><name> Idfield</name><rtexprvalue>true</rtexprvalue><description> primary key Fields </description>< /attribute><attribute><name>width</name><rtexprvalue>true</rtexprvalue>< description> Table Width </description></attribute><attribute><name>height</name>< rtexprvalue>true</rtexprvalue><description> Table Height </description></attribute>< attribute><name>checkbox</Name><rtexprvalue>true</rtexprvalue><description> Whether the check box is displayed </description></ attribute><attribute><name>fit</name><rtexprvalue>true</rtexprvalue>< Description> whether the parent container is fit, true defaults, False</description></attribute><attribute><name>sortname </name><rtexprvalue>true</rtexprvalue><description> sort the columns that are defined </description></ Attribute><attribute><name>sortorder</name><rtexprvalue>true</rtexprvalue> <description> defines the sort order for columns, which can only be "increment ASC" or "Descending desc" </description></attribute><attribute><name >fitColumns</name><rtexprvalue>true</rtexprvalue><description> when True, the size of the auto-expand/Contract column, To fit the width to prevent horizontal scrolling </description></attribute><attribute><name>showPageList</name>< Rtexprvalue>true</rtexprvalue><description> whether to show page list </description></attribute>< Attribute><name>showrefresh</name><rtexprvalue>true</rtexprvalue><description> whether the Refresh button is displayed </description> </attribute><attribute><name>showtext</name><rtexprvalue>true</rtexprvalue ><description> Whether paging information is displayed </description></attribute><attribute><name>style</ name><rtexprvalue>true</rtexprvalue><description> Table Style Easyui,datatables</description ></attribute><attribute><name>pagesize</name><rtexprvalue>true</ Rtexprvalue><description> shows the number of bars per page </description></attribute><attribute><name> Onloadsuccess</name><rtexprvalue>true</rtexprvalue><description> data is loaded into the calling method </ Description></attribute><attribute><name>ondblclick</name><rtexprvalue>true </rtexprvalue><description> Double-click Invoke method </description></attribute><attribute><name >onClick</name><rtexprvalue>True</rtexprvalue><description> Click Invoke method tree under function (RowData), DataGrid under Function (Rowindex,rowdata) </description></attribute><attribute><name>queryMode</name><rtexprvalue> true</rtexprvalue><description> Query mode: single (conditional query: Default), group (combination query) </description></attribute ><attribute><name>autoLoadData</name><rtexprvalue>true</rtexprvalue>< Description> List page data load mode. True to load data automatically, false to load manually, default to True</description></attribute><attribute><name>openfirstnode </name><rtexprvalue>true</rtexprvalue><description> is not to expand the first node, in the case of a tree, true expands, False does not expand default false</description></attribute><attribute><name>entityname</name>< Rtexprvalue>true</rtexprvalue><description> the corresponding Entity object, if both the entity and Controller are rules can not be filled out, automatic completion of the label to do the association </ Description></attribute><attribute><name>rowstyler</name><rtexprvalue>true </rtexThe Prvalue><description> line CSS function specifies the name of the call, which is called functionname (Index,row) to invoke </description></attribute ><attribute><name>extendParams</name><rtexprvalue>true</rtexprvalue>< Description>datagrid extension field, if Easyui above but JEECG does not have this attribute can add themselves add rules and easyui field consistent </description></ Attribute></tag></taglib>
Third, calling code
<t:datagrid sortname= "createdate" sortorder= "desc" name= "tablepropertylist" title= "" fitcolumns= "false" ActionUrl = "" "Idfield=" id "fit=" true "querymode=" group "checkbox=" true "></t:datagrid>
Four, the interface effect
Summary :
The following figure depicts a process in which a container loads custom labels:First Callsetpagecontentmethod,JSPthe engine willJSPimplicitly created when the page is converted.PageContextobject is called as a parametersetpagecontentmethod, and then calls thegetParent,setParentmethod to set the parent tag object, and then call allSettermethod to assign all variables to a value, and the first three steps are completed before callingdoStartTagmethod that marks the beginning of the real label processing;Doendtagmeans that the label processing is finished. Called after all of the same label processing has endedReleasemethod to remove the label from memory.
Java Writing Custom Labels