如何从支持bean中突出显示Primefaces树节点 [英] How to highlight a primefaces tree node from backing bean

查看:116
本文介绍了如何从支持bean中突出显示Primefaces树节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用primefaces树组件.该树有一个上下文菜单(添加节点,编辑节点,删除节点).执行完一些操作后,我需要刷新树,然后突出显示添加或编辑的节点.

I am working with primefaces tree component. There is a context menu for the tree (add a node, edit node, delete node). After performing some operation, I need to refresh the tree and then highlight the node added or edited.

这是我的代码.

        <p:treeNode>
            <h:outputText value="#{node}" />
        </p:treeNode>
    </p:tree>
    <p:contextMenu for="pTree" id="cmenu">
        <p:menuitem value="Add topic as child" update="pTree, cmenu"
                    actionListener="#{treeBean.addChildNode}" />
         <p:menuitem value="Add topic Below" update="pTree, cmenu"
                    actionListener="#{treeBean.addTopicBelow}" />
         <p:menuitem value="Delete Topic" update="pTree, cmenu"
                    actionListener="#{treeBean.deleteNode}" />
    </p:contextMenu>

treeBean.java

公共类TreeBean实现了可序列化的{

treeBean.java

public class TreeBean implements Serializable {

private TreeNode root;

public TreeBean() {
    root = new DefaultTreeNode("Root", null);
    // GET the root nodes first L0
    List<TracPojo> rootNodes = SearchDao.getRootNodes111();
    Iterator it = rootNodes.iterator();

    while (it.hasNext()) {

        TracPojo t1 = (TracPojo) it.next();

        String tid = t1.getTopicID();

        TreeNode node1 = new DefaultTreeNode(t1, root);

    }


}
 public TreeNode getRoot() {
    return root;
 }


public void addChildNode(ActionEvent actionEvent) 
{

    List record = NewSearchDao.getRecord(selectedNode);

    Iterator it = record.iterator();
    while (it.hasNext()) {
        Object[] record1 = (Object[]) it.next();
        setParentID_dlg((String) record1[0]);
        setSortIndex((Integer) record1[2]);
    }

}

public void saveChilddNode() {
    System.out.println("Save as Child Node ........");

}

}

推荐答案

除非将声明为 selection =#{treeBean.selectedNode}" 的selectedNode设置为null,否则为已经选择并且您唯一要做的就是从触发组件更新树组件;您的情况是:

Unless you set the selectedNode, which you declare as selection="#{treeBean.selectedNode}", to null, it is already selected and the only thing you have to do is to update the tree component from the triggering component; in your case it is:

<p:menuitem update=":yourForm:pTree"   /*rest of the stuff*/    />

这篇关于如何从支持bean中突出显示Primefaces树节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆