xtree在struts下动态加载树

 显示树的页面

 

< script type = " text/javascript " >

var tree 
=   new  WebFXLoadTree( " Hello World " "treeView.do " );
tree.write();

</ script >

treeView.do对应的action方法

 

public  ActionForward execute(ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response)
{
        
if(form instanceof TreeForm){
            
try {
                TreeForm f 
= (TreeForm)form;
                TreeBo bo 
= new TreeBo();
                bo.getTreeList(f.getDeptNo(),response);
            
            }
 catch (IOException e) {
                e.printStackTrace();
            }
 catch (NamingException e){
                e.printStackTrace();
            }
 catch (SQLException e){
                e.printStackTrace();
            }

        }

        
return null;
    }

action调用的方法

 

public   void  getTreeList(String deptNo,HttpServletResponse response)  throws  SQLException,IOException {
        Connection t 
= dataSource.getConnection();
        PreparedStatement p 
= t.prepareCall("select a.deptname name,a.deptcode code,(select count(b.deptcode)-1 from t_dept b where b.deptcode like a.deptcode||'%') num from t_dept a where length(a.deptcode)=nvl(length(?),0)+4 and a.deptcode like ? || '%'");
        String tmp 
= deptNo;
        p.setString(
1,deptNo);
        p.setString(
2,tmp);
        ResultSet set 
= p.executeQuery();
        response.setCharacterEncoding(
"gb2312");
        response.setContentType(
"text/xml charset=gb2312");
        PrintWriter out 
= response.getWriter();
        out.write(
"<?xml version="1.0" encoding="gb2312"?>");
        out.write(
"<tree>");
        
while(set.next()){
            out.write(
"<tree text="&quot;"+set.getString("name")+"&quot;" "+(set.getInt("num")>0?"src="treeView.do?deptNo="+set.getString("code")+""":"action="xxx.html"")+"/>"); 
        }

        out.write(
"</tree>");
        out.flush();
        set.close();
        p.close();
        t.close();
    }

通过sql得到此级别的全部元素和每个此级别元素所包含的子元素数量,以便判断在显示层是否需要显示 “+“ 号

欢迎交流

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值