首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

怎么在JSP中显示树形结构的数据

2013-02-20 
如何在JSP中显示树形结构的数据项目中需要显示部门信息,请问在JSP页面中如何显示呢?JSP[解决办法]Struts2

如何在JSP中显示树形结构的数据
项目中需要显示部门信息,请问在JSP页面中如何显示呢? JSP
[解决办法]
Struts2动态树型从数据库取出 
后台数据层代码:

public TEquipmentTree[] getChildren(String treeNodeId) throws Exception {
  Connection conn = getConnection();
  PreparedStatement smt = conn.prepareStatement("select * from t_equipmentclass where eql_pcode ='"+treeNodeId+"'");
  
  ResultSet rs = smt.executeQuery();
  List<TEquipmentTree> childList = new ArrayList<TEquipmentTree>();
  while (rs.next()) {
   TEquipmentTree TEquipmentTree = new TEquipmentTree();
   TEquipmentTree.setEqlCode(rs.getString("eql_code"));
   TEquipmentTree.setEqlName(rs.getString("eql_name"));
   TEquipmentTree.setEqlPcode(rs.getString("eql_pcode"));
   TEquipmentTree.setEqlLevel(rs.getInt("eql_level"));
   TEquipmentTree.setEqlRemark(rs.getString("eql_remark"));
   TEquipmentTree.setChildEquipment(getChildren(TEquipmentTree.getEqlCode()));
   childList.add(TEquipmentTree);
  }
  rs.close();
  smt.close();
  conn.close();
  TEquipmentTree[] childResult = new TEquipmentTree[childList.size()];
  childResult = childList.toArray(childResult);
  return childResult;
 }

public TEquipmentTree[] getAllTEquipmentTree() throws Exception {
  String sql="select * from T_Equipmentclass where EQL_PCODE='EEW1001'";
  Connection conn = getConnection();
  PreparedStatement smt = conn.prepareStatement(sql);
  ResultSet rs = smt.executeQuery();
  List<TEquipmentTree> TEquipmentTreeList = new ArrayList<TEquipmentTree>();
  while (rs.next()) {
   TEquipmentTree TEquipmentTree = new TEquipmentTree();
   TEquipmentTree.setEqlCode(rs.getString("EQL_CODE"));
   TEquipmentTree.setEqlName(rs.getString("EQL_NAME"));
   TEquipmentTree.setEqlPcode(rs.getString("EQL_PCODE"));
   TEquipmentTree.setEqlLevel(rs.getInt("EQL_LEVEL"));
   TEquipmentTree.setEqlRemark(rs.getString("EQL_REMARK"));
   TEquipmentTree.setChildEquipment(getChildren(TEquipmentTree.getEqlCode()));
   TEquipmentTreeList.add(TEquipmentTree);

  }
  rs.close();
  smt.close();
  conn.close();
  TEquipmentTree[] TEquipmentTree = new TEquipmentTree[TEquipmentTreeList.size()];
  TEquipmentTree = TEquipmentTreeList.toArray(TEquipmentTree);
  return TEquipmentTree;
 }

前台页面:

<s:head theme="ajax"/>
<script type="text/javascript">
function treeNodeSelected(arg) {
 window.returnValue=arg.source.title+","+arg.source.widgetId;
 window.close();
 //arg.source.widgetId+","
 //window.opener.document.getElementById("eqlCode").value=arg.source.widgetId;
 //alert(arg.source.title);
 //window.opener.document.getElementByName("eqlName").value=arg.source.title;
 //alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] selected");


   }
   dojo.addOnLoad(function() {                
      var s = dojo.widget.byId('tree').selector;                
      dojo.event.connect(s, 'select', 'treeNodeSelected');
   });
</script>
</head>
<body>
<s:form>
 <s:tree id="tree" 
 rootNode="root"
 nodeIdProperty="eqlCode" 
 nodeTitleProperty="eqlName" 
 childCollectionProperty="childEquipment" 
 treeSelectedTopic="treeSelected" 
 theme="ajax" 
 showRootGrid="false">
 </s:tree>
</s:form>

热点排行