2) delete a person
Deleting a person is also implemented by calling the deleteperson method in the org. jsp file. This method passes the deleted person ID. How to determine whether a person's ID is to read hidden IDs and scan the entire table to see the selected ones. Here we should note that multiple options are provided.
Function deleteperson (){
For (VAR I = 0; I <tblist. Rows. length; I ++ ){
VaR ROW = tblist. Rows [I]. cells [0]. Children [0]. Rows [0];
If (row. cells [0]. Children [0]. Checked)
{
VaR personid = row. cells [1]. Children [0]. value;
If (personid> 0)
{
VaR XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
XMLHTTP. Open ("Post", "org. jsp? Mode = deleteperson & personid = "+ personid, false );
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHTTP. Send ();
}
Tblist. deleterow (I );
I --;
}
}
}
3) editors
We need to determine which rows have been modified. Newly Added but not saved rows should be added rather than modified.
Function save (){
If (modifyorg () = "N ")
{
Return;
}
For (VAR I = 0; I <tblist. Rows. length; I ++)
{
VaR ROW = tblist. Rows [I]. cells [0]. Children [0]. Rows [0];
VaR personid = row. cells [1]. Children [0]. value;
VaR seqno = tblist. Rows [I]. getattribute ("seqno ");
VaR staffnode = persondom. selectsinglenode ("// peorsone [@ seqno = '" + seqno + "']");
VaR personcode = row. cells [2]. Children [0]. value;
VaR personname = row. cells [3]. Children [0]. value;
VaR sex = row. cells [4]. Children [0]. value; // alert (staffn; ODE );
If (staffnode. getattribute ("isnew") = "Y ")
{
Createperson (currnodeid, personcode, personname, sex );
}
Else
{
VaR strxml = "<? XML version = '1. 0' encoding = 'gb2312 '?> "+
"<DATA>" +
"<Personcode> <! [CDATA ["+ personcode +"]> </personcode> "+
"<Personname> <! [CDATA ["+ personname +"]> </personname> "+
"<Sex> <! [CDATA ["+ sex +"]> </sex> "+
"<Personid> <! [CDATA ["+ personid +"]> </personid> "+
"</Data> ";
// Alert (strxml );
VaR XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
XMLHTTP. Open ("Post", "org. jsp? Mode = modifyperson ", false );
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHTTP. Send (strxml );
}
}
}
Iv. xml and XSL file Design
XML is an extensible markup language. It has an open, scalable, and self-describing language structure and has become a standard for online data and document transmission. XSLT aims to separate information content from Web display. HTML defines display by abstract concepts (such as paragraphs, highlights, and number lists) to achieve device independence. XSLT is used to display controls and set the control style.
Ajax mainly uses XML and XSLT for data exchange and processing.
1. xml file of tree information (see root. xml file)
XML is a markup language, and elements must appear in pairs. Tree is the root node in the tree structure, and item is the node body. The attribute text indicates the text displayed by the node, and the ID indicates the unique ID.
<? XML version = '1. 0' encoding = 'gb2312 '?>
<Tree id = "0">
<Item child = "1" text = "Organization" id = "1">
</Item>
</Tree>
This file is not necessary, but only for the system to run independently. In fact, it is unnecessary to connect the background data. All you need is orgtree. loadxml ("root. xml? 0 ") changed to orgtree. loadxml (" org. jsp.
2. xml file of personnel information (see peorson. xml file)
Note! [CDATA [] any text in any format can be displayed, and any other characters can be inserted in the text. This file is not necessary either.
3. XSL file for Personnel Information Display (see addorgperson. XSL file)
The XSL file is also in XML format. Therefore, XML standards are observed. The following describes the main topics:
<? XML version = "1.0" encoding = "gb2312"?>
// This is the first line defining the XML file. Used to specify the version and Character Set
<XSL: stylesheet xmlns: XSL = "http://www.w3.org/TR/WD-xsl" Language = "JavaScript">
// The stylesheet element is defined here. The organization and language of the International naming convention.
<XSL: template match = "/">
<XSL: Apply-templates select = "peorsones"/>
</XSL: Template>
// The above is the matching rule. "/" Indicates matching from the root knot. Match the following peorsones tag. This is related to regular expressions. We only need to understand it.
<XSL: template match = "peorsones">
// What to do when peorsones is matched.
<Table id = "tblist" border = "1" width = "100%">
// Define a table with ID "tblist. This table is displayed on the web
<XSL: For-each select = "peorsone">
// Cyclically match peorsone
<Tr>
// Define a row in the tblist table and add a property name named seqno on the row. The value is the matched seqno (serial number)
<XSL: attribute name = "seqno"> <XSL: value-of select = "@ seqno"/> </XSL: attribute>
<TD>
// Define a column on the row and match the column again
<XSL: Apply-templates select = "."/>
</TD>
</Tr>
</XSL: For-each>
</Table>
</XSL: Template>
<XSL: template match = "peorsone">
<Table border = "1" width = "100%">
<Tr>
// Define a column with a width of 5% and insert a checkbox control into the column
& Lt; TD width = "5%" & gt;
<Input type = "checkbox" value = "on" size = "10"> </input>
</TD>
// Define a non-displayed column and insert a text control into the column. The text value is the matched personid (person ID)
<TD style = "display: none">
<Input type = "text" size = "25">
<XSL: attribute name = "value"> <XSL: value-of select = "personid"/> </XSL: attribute>
</Input>
</TD>
& Lt; TD width = "30%" & gt;
<Input type = "text" size = "20">
<XSL: attribute name = "value"> <XSL: value-of select = "personcode"/> </XSL: attribute>
</Input>
</TD>
& Lt; TD width = "40%" & gt;
<Input type = "text" size = "40">
<XSL: attributename = "value"> <XSL: value-of select = "personname"/> </XSL: attribute>
</Input>
</TD>
// Define a column with a width of 28% and insert a select control in this column. If the select value matches 0, it is male ", 1 is "female"
& Lt; TD width = "28%" & gt;
<Select size = "1">
<Option value = "0">
<XSL: If test = ". [sex = 0]">
<XSL: attribute name = "selected"> true </XSL: attribute>
</XSL: If>
Male
</Option>
<Option value = "1">
<XSL: If test = ". [sex = 1]">
<XSL: attribute name = "selected"> true </XSL: attribute>
</XSL: If>
Female </option>
</SELECT>
</TD>
// Define a column and insert a button control into the column. The onclick event is a custom method, which is passed to the button currently clicked
<TD width = "*">
<Button onclick = "openpersonrolepage (this)" style = "width: 36; Height: 21"> role </button>
</TD>
</Tr>
</Table>
</XSL: Template>
</XSL: stylesheet>
V. Real-time Data Interface (see org.jpg file)
The Org. jsp file is used to build a bridge between the Java class running on the server and the front-end web page. Obtain the middleware interface.
Analysis SectionCode:
<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "tool. *" %>
<% @ Page import = "orgnew. *" %>
<% @ Page import = "org. W3C. Dom. *" %>
// The above mainly references some Java classes
<%
Try {
// Request. setcharacterencoding ("GBK ");
Document Doc = xmltool. createdocumentfromrequest (request );
// Create a document object for a web-based document request
Connection conn = conntool. getconnectionfrompool ();
// Obtain the Request Method Name
String mode = request. getparameter ("Mode ");
// Out. println ("CCC ");
// If there are no other parameters in the method, read the Organization tree data
If (mode = NULL ){
/* Int orgid = integer. parseint (request. getparameter ("ID "));
String STR = orgmanager. getchildorg (orgid, Conn );
Out. println (STR );
*/
String STR = orgmanager. gettree (conn );
// Out. println (STR );
Out. println (STR );
} Else if (mode. Equals ("createorg ")){
// If the createorg method is used, an organization is created.
Int parentorgid = integer. parseint (request. getparameter ("parentorgid "));
// Retrieve the first passed parameter parentorgid
Int orgid = orgmanager. createorg (parentorgid, Conn );
// Call the createorg method of the orgmanager class to create an organization
Out. println (orgid );
// Return results
}
Conn. Close ();
}
Catch (exception e ){
E. printstacktrace ();
}
%>