Model Select:表格要展示的数据
Tree DataSource:树的数据源
数据源是自定义java类
实现接口:ITreeRetriever创建根节点、判断子节点、创建子节点

--数据源

package com.haiyisoft.bill.page.tree;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.haiyisoft.entity.UepContract;
import com.haiyisoft.entity.UepCustomer;
import com.haiyisoft.ep.common.jpa.util.JPAUtil;
import com.haiyisoft.ep.common.model.QueryParam;
import com.haiyisoft.ep.common.model.QueryParamList;
import com.haiyisoft.ep.framework.model.ITreeRetriever;
import com.haiyisoft.ep.framework.model.TreeBean; public class TreeSourceDP implements ITreeRetriever { @Override
public TreeBean createTree(String arg0) {
TreeBean root = new TreeBean();
if(arg0 != null && "".equals(arg0)){
root.setCode("0");
}else{
root.setCode(arg0);
}
root.setLabel("客户合同树根");
root.setType("ROOT"); return root;
} @Override
public boolean hasChild(TreeBean arg0) {
return this.retrieveNode(arg0).size()>0;
} @Override
public List<TreeBean> retrieveNode(TreeBean arg0) {
List<TreeBean> list = new ArrayList<TreeBean>();
if("ROOT".equals(arg0.getType())){
List<UepCustomer> dataList = JPAUtil.loadAll(UepCustomer.class);
for(UepCustomer entity : dataList){
TreeBean node = new TreeBean();
node.setCode(entity.getId().toString());
node.setLabel(entity.getCustomerName());
node.setType("CUSTOMER");
//向前台传递参数或属性
Map<String,String> extProp = new HashMap<String,String>();
extProp.put("config", node.getCode()+"_"+node.getLabel());
node.setExtProp(extProp); list.add(node);
}
}else if("CUSTOMER".equals(arg0.getType())){
QueryParamList params = new QueryParamList();
params.addParam("customerId",new BigDecimal(arg0.getCode()));
List<UepContract> dataList = JPAUtil.load(UepContract.class,params);
for(UepContract entity : dataList){
TreeBean node = new TreeBean();
node.setCode(entity.getId().toString()); node.setLabel(entity.getContractName());
node.setType("CONTRACT");
list.add(node);
}
} return list;
} }
05-11 20:48