How to select node surface tree from bean backup

I work with a surface tree component. There is a context menu for the tree (add node, edit node, delete node). After doing some operation, I need to update the tree, and then select the node the added or edited file.

This is my code.

index.xhtml

        <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

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

}

}

0
source share
2 answers

Feathers p:treeNodehas an attribute styleClass. You can install this dynamically with your bean support. The view will look like this:

<p:tree>
  <p:treeNode styleClass="#{treeBean.styleClass}">
    <h:outputText value="#{node}" />
  </p:treeNode>
</p:tree>

Then add the styleClass element to your TreeBean using the get / set method, which returns a string representing the style class:

public class TreeBean implements Serializable {
  private String styleClass;
  ...
  public String getStyleClass() {
    // your style selection logic here
  }
  ...
}

Remember to add style classes to your css.

+1

Node, selection = "# {treeBean.selectedNode}" , null, , , , ; :

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

All Articles