title: how to update Tree table which is a session scoped and resolving the issue of command button for intermediate nodes
body: <p>I am working on prime faces tree table. I have a list of students and for each students I am trying to display all possible teachers they can undergo training. </p>
  
  <p>I have kept managed bean class named TreeviewBean which is a session scoped and I have a constructor where I am initializing the root value as shown below. I have initialized inside a constructor and not in get root method. Initially constructor gets called for first time and tree table works absolutely fine. Problem comes when new students are created in different page. since the tree view bean is session scoped, constructor is not calling every time and list of students is not updating as a result tree view is not displaying the right value. I have changed to request scope, here performance hinders and command button on editing teachers fails. How could I solve the problem?</p>
  
  <pre><code>     @ManagedBean(name="treeViewBean")
       @SessionScoped
       public class TreeViewBean implements Serializable {  
  
              private static final long serialVersionUID = 1L;
  
              private Object selectedNode;
  
              private TreeNode root;  
  
              private TreeData treedata;
  
              public TreeViewBean() {  
                 systemstud= new ManageStudentsDelegate();
                 list  sys = systemstud.getAllnfo();
                 root = new DefaultTreeNode("root", null);
                 for(StudBean s : sys){
                  treedata= new TreeData(s,"students");
                      TreeNode system = new DefaultTreeNode(treedata, root); 
                      if(s.getteachers()!=null){
                    for(teachBean serv : s.getteachers()){
                       treedata= new TreeData(serv,"teachers");
                       TreeNode service = new DefaultTreeNode(treedata, system);
                     }
                      }
                 }
              }     
  
              public TreeNode getRoot() { 
                  return root;  
              }  
  
              public void setRoot(TreeNode root) {  
                  this.root = root;  
              }  
  
              public String editStudentOrteacher(){
                               system.out.println("edit");
              }
  
              public Object getSelectedNode() {
                  return selectedNode;
              }
  
              public void setSelectedNode(Object selectedNode) {
                  this.selectedNode = selectedNode;
              }
     }        
  </code></pre>
  
  <p>XHTML Code:</p>
  
  <pre><code> &lt;p:treeTable value="#{treeViewBean.root}" var="system"  id="treeTable"&gt;  
  
          &lt;p:column style="width:150px" &gt;  
              &lt;f:facet name="header"&gt;  
                  Name  
              &lt;/f:facet&gt;  
              &lt;h:outputText value="#{system.stud.name}" /&gt; 
              &lt;h:outputText value="#{system.teach.name}"/&gt; 
          &lt;/p:column&gt;  
          &lt;p:column &gt;
              &lt;p:commandButton action="#{treeViewBean.editStudentOrteacher}" process="@this"&gt;
              &lt;f:setPropertyActionListener target="#{treeViewBean.selectedNode}" value="#{system}"&gt;&lt;/f:setPropertyActionListener&gt;
              &lt;/p:commandButton&gt;
         &lt;/p:column&gt;
  
   &lt;/p:treeTable&gt;
  </code></pre>