Struts Development Practice - Implementation of Simple Tree
The main function of this case is to complete a simple tree written in Java language. The advantage is that the code of the JSP page is simple and clean. A disadvantage is that each operation is going to go to the server and then take a data. Recently, I found a JavaScript written in http://www.aspaid.com/, mix the JS code with the Java code, which can get a full-time tree, and the data can be taken from the server side from the server. try it. The following describes the code example of the former method.
Define MyTreeForm
Package test;
Import org.apache.struts.action. *;
Import javax.servlet.http. *;
Public Class MyTreeform
EXTENDS ACTIONFORM {
/ ** ID number * /
Private int ID = 0;
/**level*/
Private int discount = 0;
/**name*/
Private string text = ""
/ ** superior node * /
Private string UpIDS = "0";
/ ** Is there a child node 0: NO; 1: yes; * /
Private string haschild = "0";
/ ** Whether to expand / 0: false; 1: true; * /
Private string ifxpanded = "0";
/ ** Is there a next node 0: false; 1: True; * /
Private string havenext = "0";
/ ** Is 0: Visible; 1: unvisible; * /
Private string isvisible = "0";
/ ** Node link string * /
Private string link = "null";
Public void setHavechild (string haschild) {
THISHAVECHILD = HAVECHILD;
}
Public string gethavechild () {
Return Havechild;
}
Public void sethavenext (string haventext) {
THISHAVENEXT = HAVENEXT;
}
Public string gethavenext () {
Return haventext;
}
Public void setifexpanded (String ifxpanded) {
THIS.IFEXPANDED = IFEXPANDED;
}
Public string getifexpanded () {
Return iFexpanded;
}
Public void setisvisible (String isvisible) {
THIS.ISVisible = isvisible;
}
Public string getisvisible () {
Return isvisible;
}
Public void setLink (String link) {
This.Link = LINK;
}
Public string getLink () {
Return Link;
}
Public void setid (int id) {
THIS.ID = ID;
}
Public int getId () {
Return ID;
}
Public void setlevel (int level) {
THIS.LEVEL = Level;
}
Public int getLevel () {
Return Level;
}
Public void setState (string state) {
THIS.STATE = State;
}
Public string getState () {
Return State;
}
Public void setText (string text) {
THIS.TEXT = TEXT;
}
Public string gettext () {
Return TEXT;
}
Public void setupids (String Upids) {
THIS.UPIDS = UPIDS;
}
Public string getupids () {
Return UpIDS;
}
Public ActionerRors Validate (ActionMapping ActionMApping,
HttpservletRequest httpservletRequest) {
/ ** @ Todo: Finish this method, this is just the skeleton. * /
Return NULL;
}
Public Void Reset (ActionMapping ActionMApping,
HttpservletRequest httpservletRequest) {
}
}
2. You can store the result set of the trees you want to display, and store it in a new list according to the style of MyTreeForm.
3. JSP display code excerpt:
<% @ page contenttype = "text / html; charset = GBK"%>
<% @ Taglib Uri = "/ bean" prefix = "bean"%>
<% @ Taglib URI = "/ HTML" prefix = "html"%>
<% @ Taglib Uri = "/ Logic" prefix = "logic"%>
|