1 Reply Latest reply on Jan 27, 2009 5:22 PM by judy guglielmin

    Navigation Tree refreshing issue

    Govind Mishra Newbie
      package org.web.action;

      import javax.faces.context.FacesContext;
      import javax.faces.event.ActionEvent;
      import javax.swing.tree.DefaultMutableTreeNode;
      import javax.swing.tree.DefaultTreeModel;

      import org.navigation.NavigationBean;
      import org.web.navigation.TreeNodeListener;
      import org.web.service.Service;
      import org.service.ServiceException;

      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.Unwrap;
      import org.jboss.seam.faces.FacesMessages;

      import com.icesoft.faces.async.render.RenderManager;
      import com.icesoft.faces.async.render.Renderable;
      import com.icesoft.faces.webapp.xmlhttp.RenderingException;
      * For Tree
      public class Tree implements Serializable,TreeNodeListener,Renderable {

           //private IntervalRenderer ir;
           private PersistentFacesState state = PersistentFacesState.getInstance();
           private static final long serialVersionUID = 1L;
           private RenderManager renderManager;
           protected FacesMessages facesMessages;
           public static final String TREE_ROOT_NAME = "trees";

           private DefaultTreeModel tree;
           int i=0;
           private Service service;
           private NavigationBean navigationBean;
           private String loggedInUser;
           private String sessionId;

           public DefaultTreeModel getTree() {
                state = PersistentFacesState.getInstance();
                if (tree == null) {
                     tree = new DefaultTreeModel(getTreeRoot());
                     List<Test> tests = null;
                          tests = service.getTests();
                          Collections.sort(tests,Test.getComparator("urName", true));
                     } catch(ServiceException e){
                          facesMessages.add(StatusMessage.Severity.ERROR," Service Error: {0}", e.getMessage());
                          tests = new ArrayList<Test>();
                          tests.add(new Realm(new User(loggedInUser,null,null)));// Let's add the user's realm to the list.
                     if (tests != null) {
                          for (Test test : tests) {
                               DefaultMutableTreeNode branchNode = new DefaultMutableTreeNode();
                               UserObject branchObject = new UserObject(branchNode,test,navigationBean);
                               //Let's set selected test to loggedInUser                         
                               ((DefaultMutableTreeNode) tree.getRoot()).add(branchNode);
                          //register for navigation event.          
                return tree;

           public PersistentFacesState getState() {
                return state;
           private  DefaultMutableTreeNode getTreeRoot() {
                Test root = new Test();
                root.setUser(new User());
                DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode();
                UserObject rootObject = new UserObject(rootTreeNode,root,navigationBean);
                return rootTreeNode;
            public void renderingException( RenderingException re) {
                 facesMessages.add("Interval Render Stopped");
           //      cleanup();

      /*       private void cleanup() {
                   if (ir != null) {
                       if (ir.isEmpty() ) {
                            facesMessages.add("Interval Render Stopped");
            * Reset's the selected variable of a UserObject.
            * @param node
           private void resetTreeNodeSelection(DefaultMutableTreeNode node){
                UserObject root = (UserObject)node.getUserObject();
                Enumeration enumer = node.children();
                while (enumer.hasMoreElements()) {
                     DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) enumer.nextElement();
            * Reset the selected flag of all tree nodes.
           public void handleTestSelected(Test selectedTest) {          
                resetTreeNodeSelection((DefaultMutableTreeNode) tree.getRoot());

            * @return the renderManager
           public RenderManager getRenderManager() {
                return renderManager;

            * @param renderManager the renderManager to set
           public void setRenderManager(RenderManager renderManager) {
                state = PersistentFacesState.getInstance();
           //     state.addViewListener(this );
      /*       FacesContext fc = FacesContext.getCurrentInstance();
              synchronous = (String) fc.getExternalContext().getInitParameterMap().
                      get( "com.icesoft.faces.synchronousUpdate" );
      is "+synchronous);
                sessionId = FacesContext.getCurrentInstance().getExternalContext().getSession(false).toString();
                System.out.println("session Id is "+sessionId);
                if (i<2)


      by clicking on Tree Node, Popup menu displays from where we can add or remove Tree node. its working fine but after adding or removing Tree node navigation tree should refresh. So please help me or suggest me what I can do for Tree refreshing.

      If u need any clarification please write me on mishragovindi@gmail.com

      Advance Thanks,