Hello all,

I've got question to Sean (well, maybe someone else could help me as well).

I'm developing an admin console for my company. All employers are using browser with java script enabled so I decided to use tree2 with clientSideToggle set to "true". What my problem is, when I delete LAST subcategory in EXPANDED category node, I've ServletException about expanded leaf - well, it's logical, I deleted last subnode, so parent has become leaf and cannot be expanded. I using the following code (in my backing bean - actually it's PageBean 'cause I'm using Creator 2) to collapse path to deleted node and expand new path without deleted node. It doesn't work - I event tried to use toggleExpand() on this node - no results. Still error "Encountered node [0:0:0:2:3] + in illogical state ...". Could anyone give me a hint how to fix it? I believe the problem is that the old tree is somewhere cached and my methods called in backing bean doesn't update it. That's my code:


public String removeButton_action() {
       categoryTree.setNodeId(selectedNodeId);
       if(!categoryTree.getNode().isLeaf()) {
messageStaticText.setText("Selected category is not empty. Delete all subcategories first."
                   );return null;
       }
       else if(selectedCategoryId == 0) {
messageStaticText.setText("Category not selected or not exists.");
           return null;
       }

javax.swing.JOptionPane confirmDialog = new javax.swing.JOptionPane();
       confirmDialog.grabFocus();
       int i = confirmDialog.showConfirmDialog(new javax.swing.JFrame(),
               "Are you sure you want to delete this category?", "Confirm",
               javax.swing.JOptionPane.YES_NO_OPTION);
       if(i ==
               javax.swing.JOptionPane.YES_OPTION) {
           String[] selectionPath =
                   categoryTree.getPathInformation(selectedNodeId);
           for(int k=0;k<=selectionPath.length-1;k++) {
System.out.println("selectionPath["+k+"]: " + selectionPath[k]);
           }


           categoryTree.collapsePath(selectionPath);


           // skiping last node as it has been deleted
           String[] newSelectionPath = new String[selectionPath.length-1];
           for(int j = 0; j <= selectionPath.length - 2; j++) {
               newSelectionPath[j] = selectionPath[j];
           }

           for(int k=0;k<=newSelectionPath.length-1;k++) {
System.out.println("newSelectionPath["+k+"]: " + newSelectionPath[k]);
           }


           categoryTree.expandPath(newSelectionPath);
           categoryTree.setNodeId(newSelectionPath[newSelectionPath.length-1]);
           categoryTree.toggleExpanded();

           selectedCategoryStaticText.setText(
                   (String)createSelectionPath(
                   newSelectionPath[newSelectionPath.length-1]));

           categoryTree.setNodeId(newSelectionPath[newSelectionPath.length-1]);

           categoryTree.getDataModel();

           CategoryData.removeCategory(
               new Integer(selectedCategoryId));
           clearEditRemoveTabFields();

           selectedCategoryId = 0;

           return "delete";
               }
       else
           return null;
   }


Michael


Reply via email to