JSF mufaces的Tree2 组件
1、数据库表结构:
create table MENU
(
MENUID NUMBER(10) not null,--自增1id
MENU VARCHAR2(20) not null,--MENU名称
MENULINK VARCHAR2(200),--MENU连接
MENUSEQ VARCHAR2(1024) not null,--序列
ISMENU NUMBER(2),--是否最后一级
UPID NUMBER(10) not null--上级ID
);
alter table AQ_MENU
add constraint AQ_MENU_ID primary key (MENUID)
using index
tablespace AQ;
2、使用递归算法生成TreeNode结构:
package test;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import org.apache.myfaces.custom.tree2.TreeModel;
import org.apache.myfaces.custom.tree2.TreeModelBase;
import org.apache.myfaces.custom.tree2.TreeNode;
import org.apache.myfaces.custom.tree2.TreeNodeBase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import aq.commons.FacesUtils;
import aq.kaohzd.AqKaohzd;
import aq.kaohzd.BaseBean;
public class TreeTest extends BaseBean implements Serializable {
private TreeNode treeNode = null;
private String docNum = null;
public String getDocNum() {
String s=FacesUtils.getRequestParameter("docNum");
this.setDocNum(s);
return this.docNum;
}
public void setDocNum(String docNum) {
this.docNum = docNum;
}
public TreeNode getTreeNode() {
if (treeNode == null) {
this.parseTree();
}
return this.treeNode;
}
public void setTreeNode(TreeNode treeNode) {
this.treeNode = treeNode;
}
public void parseTree() {
this.treeNode = getTreeNodeBase(new AqKaohzd());
}
public TreeNodeBase getTreeNodeBase(AqKaohzd aqKaohzd) {
TreeNodeBase treeData = null;
List list = null;
try {
list = this.getKaohzdService().findAqKaohzdsByUpid(aqKaohzd);
} catch (Exception e) {
e.printStackTrace();
}
int l = list.size();
if (aqKaohzd.getUpid() == 0) {
treeData = new TreeNodeBase("myfolder", "考核字典", false);
treeData.setIdentifier("id="+0);
} else {
if (l > 0) {
treeData = new TreeNodeBase("myfolder", aqKaohzd.getWentname(), false);
} else {
treeData = new TreeNodeBase("mydocument", aqKaohzd.getWentname(), true);
}
treeData.setIdentifier("id="+aqKaohzd.getKhzdid());
}
Iterator e = list.iterator();
while (e.hasNext()) {
AqKaohzd a = (AqKaohzd) e.next();
// System.out.println(a.getKaohseq());
treeData.getChildren().add(this.getTreeNodeBase(a));
}
return treeData;
}
public TreeModel getExpandedTreeData() {
return new TreeModelBase(getTreeNode());
}
}