HttpServletRequest request = (HttpServletRequest) pageContext
.getRequest();
/* 当rootId不为空的时候,只显示rootId的子树内容,用在SingleDataEdit.jsp中选择数据时用 */
String rootId = request.getParameter("rootId");
int selectModeInt = Const.TREE_SELECT_SPREAD;
TreeService ts = TreeServiceFactory.getTreeService();
/* 得到用户拥有权限的数据,如果这些数据不为空则用这些数据构造树结构,否则用整个className对应的表来构造树结构 */
SysUserCache userCache = (SysUserCache) request.getSession()
.getAttribute(Globals.SYS_USER_CACHE);
ArrayList list = (ArrayList) userCache.getCacheData(className);
list = filterTreeList(list);
DataContextFilter filter= DataContextFilter.getInstance();
filter.setContext(userCache.getContext());
list=filter.filter(list);
Tree tree = ts.getTree(className, list);
StringBuffer buffer = new StringBuffer();
if (!GenericValidator.isBlankOrNull(selectMode))
selectModeInt = Integer.parseInt(selectMode);
if (rootId == null || rootId.equals("null"))
ts.generateWholeTree(tree, buffer, selectModeInt, functionUrl);
else {
Object root = BeanUtil.getEmptyObject(className);
Class clazz = BeanUtil.getClass(className);
String primaryKeyName = BeanUtil.getPrimaryKeyName(clazz);
BeanUtil.setFieldValue(root, primaryKeyName, new Long(rootId));
Object emptyNode = BeanUtil.getEmptyObject(root.getClass());
BeanUtil.setFieldValue(emptyNode, tree.getDisplayProperty(),
"空");
if (selectModeInt == Const.TREE_SELECT_LEAF_RETURN
|| selectModeInt == Const.TREE_SELECT_NODE_RETURN) {
ts.generateSingleNode(emptyNode, tree, 2, 1, buffer,
selectModeInt, functionUrl);
buffer.append("</div>\n");
}
ts.generateWholeSubTree(root, tree, 1, 1, buffer,
selectModeInt, functionUrl);
}
out.println(buffer);
} catch (IOException e) {
System.out.println(e.getMessage());