Richfaces Tree Binding 不能正常展开

hbzhang11 2008-08-19 10:39:12
我在页面用Tree Binding 生成树,但树不以展开..
页面代码如下:
<f:view>
<h:form id="forms">
<rich:tree id="trees" binding="#{treeAccess.tree}" nodeSelectListener="#{node.treeaAction}"></rich:tree>
</h:form>
</f:view>
类代码如下:
public HtmlTree getTree() throws IOException
{
if (tree == null){
tree = new HtmlTree();
tree.setSwitchType(UITree.SWITCH_AJAX);
tree.setStyle("width:300px");
this.bindExpression(tree, "value", "#{node.data}", TreeNode.class);
tree.setVar("item");
this.bindExpression(tree, "nodeFace", "#{item.type}", String.class);
List<UIComponent> lstChild = tree.getChildren();
lstChild.add(this.addTreeNode("Dept", "/images/bureau.gif", "/images/bureau.gif", "#{item.name}", null));
lstChild.add(this.addTreeNode("Ec", "/images/user.gif", "/images/user.gif", "#{item.name}", null));
lstChild.add(this.addTreeNode("Termi", "/images/termi.gif", "/images/termi.gif", "#{item.name}", null));
lstChild.add(this.addTreeNode("Mp", "/images/mp.gif", "/images/mp.gif", "#{item.name}", null));
}
return tree;
}

public void setTree(HtmlTree tree)
{
this.tree = tree;
}
private HtmlTreeNode addTreeNode(String type, String iconLeaf, String icon,
String expression, String function)
{
HtmlTreeNode tnode = new HtmlTreeNode();
tnode.setType(type);
tnode.setIconLeaf(iconLeaf);
tnode.setIcon(icon);
tnode.setOnselected("show('"+type+"');");
HtmlOutputText out = new HtmlOutputText();
this.bindExpression(out, "value", expression, String.class);
tnode.getChildren().add(out);
return tnode;
}
private void bindExpression(UIComponent comp, String type, String expression,
Class classes)
{
ValueExpression bind = app.getExpressionFactory().createValueExpression(ctx.getELContext(), expression, classes);
comp.setValueExpression(type, bind);
}

//数据类
public class Node extends AbstractNode implements TreeNode
{
public Node()
{
super("tree");
this.initDept();
}
private void initDept()
{
//
for (int i = 0; i < 5; i++)
{
DeptNode node = new DeptNode();
node.setId(i + "");
node.setName("Dept_" + i);
this.addChild(node.getId(), node);
for (int j = 0; j < 10; j++)
{
EcNode enode = new EcNode();
enode.setId(j + "e");
enode.setName("Ec_" + j);
node.addChild(enode.getId(), enode);
for (int k = 0; k < 10; k++)
{
TermiNode tnode = new TermiNode();
tnode.setId(j + "_" + k);
tnode.setName("Termi_" + j + "_" + k);
enode.addChild(tnode.getId(), tnode);
for (int z = 0; z < 50; z++)
{
MpNode mnode = new MpNode();
mnode.setId(j + "_" + k + "_" + z);
mnode.setName("Mp_" + j + "_" + k + "_" + z);
tnode.addChild(mnode.getId(), mnode);
}
}
}
}
}
}
...全文
220 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hbzhang11 2008-08-20
  • 打赏
  • 举报
回复
问题差不多搞定啦...如果将switchType改成client是可能正常操作的...不过用ajax就不行了,既然没回答,自已结贴啦..
hbzhang11 2008-08-19
  • 打赏
  • 举报
回复
其中,DeptNode,EcNode,TermiNode,MpNode都实现
public abstract class AbstractNode implements TreeNode
{
protected String id;

protected String name;

protected String type;

@SuppressWarnings("unchecked")
protected Map<String,TreeNode> children = new LinkedHashMap<String,TreeNode>();

@SuppressWarnings("unchecked")
protected TreeNode parent;

public AbstractNode(String type){
this.setType(type);
}

@SuppressWarnings("unchecked")
public void addChild(Object identifier, TreeNode child)
{
this.getChild().put(identifier, child);
child.setParent(this);
}

@SuppressWarnings("unchecked")
public TreeNode getChild(Object id)
{
return (TreeNode) getChild().get(id);
}

@SuppressWarnings("unchecked")
public Iterator getChildren()
{
return this.getChild().entrySet().iterator();
}

public Iterator getTreeNode(){
return this.getChild().values().iterator();
}

public Object getData()
{
return this;
}

public TreeNode getParent()
{
return parent;
}

public boolean isLeaf()
{
return this.getChild().isEmpty();
}

public void removeChild(Object id)
{
this.getChild().remove(id);
}

public void setData(Object data)
{

}

@SuppressWarnings("unchecked")
public void setParent(TreeNode parent)
{
this.parent = parent;
}

public String getId()
{
return id;
}

public void setId(String id)
{
this.id = id;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String getType()
{
return type;
}

public void setType(String type)
{
this.type = type;
}

public Map getChild()
{
return children;
}

public void setChild(Map child)
{
this.children = child;
}
}

6,787

社区成员

发帖
与我相关
我的任务
社区描述
JBoss技术交流
社区管理员
  • JBoss技术交流社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧