Tuesday, April 24, 2012

How to highlight a primefaces tree node from backing bean

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.

This is my code.


<h:outputText value="#{node}" />
<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}" />


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 ........");



No comments:

Post a Comment