9 Replies Latest reply on Apr 3, 2007 3:16 PM by nbelaevski

    Tree selection stops working after 1-2 clicks

    andrew.rw.robinson

      I am having problems with the tree stopping reporting node selection events. I tracked the problem down to the selected node value vs. the selected node input value. The node selection works 1-2 times via AJAX and then although the page submits other selections, the tree never reacts.

      What is happening when it works:
      Somewhere in the code, the "selectedNode" value and the "input" value are set to the client ID of the node the user clicks
      Then:
      The "selectedNode" parameter is set
      The "input" value is sent

      UITree decodes the "selectedNode" first, sets the selected value in the attributes of the tree
      UITree decodes the "input" and overwrites the selected value in the attributes of the tree

      Then after 1-2 node selections, the client side tree stops setting the "input" value. This value is now left as the last node that worked. So each time UITree decodes, the "selectedNode" value is correct, but the "input" value is not (it is old). As a result I never get the node selection event for the node the user just clicked.

      If I refresh the page it starts working again. The code at line 352 of UITree in version 1.1.0 is the one causing the obsolete value overwrite:

      Object selectionInputValue = requestParameterMap
       .get(getSelectionStateInputName(faces));
       if (selectionInputValue instanceof String) {
       getAttributes().put(SELECTION_INPUT_ATTRIBUTE, selectionInputValue);
       }
      


      I removed my custom code (extending the tree) to make sure it wasn't my fault and that didn't help. Any ideas? I won't be able to use the tree if I can't get this one fixed or find a work-around so any help/information is appreciated.



        • 1. Re: Tree selection stops working after 1-2 clicks
          andrew.rw.robinson

          I get this error in the LOG on the client. After this error, the tree selection stops working:

          debug[17:13:26,148]: Evaluate script replaced area in document: // Richfaces_Tree_zfpForm_memberSelectionDialog_memberSelectorTree.getNodeElements(Richfaces_Tree_zfpForm_memberSelectionDialog_memberSelectorTree, "zfpForm:memberSelectionDialog:memberSelectorTree:6");Richfaces_Tree_zfpForm_memberSelectionDialog_memberSelectorTree.getNodeElements(Richfaces_Tree_zfpForm_memberSelectionDialog_memberSelectorTree, "zfpForm:memberSelectionDialog:memberSelectorTree:3"); // //
          error[17:13:26,153]: . Error message: item has no properties


          • 2. Re: Tree selection stops working after 1-2 clicks
            andrew.rw.robinson

            More information:

            The "Tree.SelectionManager.prototype"'s method setSelection:

            setSelection:function(item){item.toggleSelection();

            Is called with item as "undefined" (causes the error).

            I can't get much more information than that because the JavaScript is horribly formatted in the browser (no newlines), so I can't get accurate line debugging.

            • 3. Re: Tree selection stops working after 1-2 clicks
              andrew.rw.robinson

              It looks like the input value's "object" of the tree is null:

               restoreSelection: function() {
               if (this.tree.input.value && $(this.tree.input.value)) {
               this.setSelection(($(this.tree.input.value)).object);
               }
               },
              

              I'm not sure where "$(this.tree.input.value)).object" comes from, but this is the problem.

              Any help? Or is no one working on the tree or is everyone just ignoring my posts?

              • 4. Re: Tree selection stops working after 1-2 clicks
                andrew.rw.robinson

                More information again. After reading up on prototype.js and looking at all the tree*.js code in the rich faces source, I now understand what is happening to a limited degree. I went into the JavaScript code and added LOG statements to all of the following events:

                tree.js->Tree.prototype->initialize
                tree.js->Tree.prototype->getNodeElements
                tree-item.js->Tree.item.prototype->initialize
                tree-item.js->Tree.item.prototype->getElements
                tree-selection.js->Tree.SelectionManager.prototype->setSelection (if item argument is null)

                This is the output when the tree breaks:

                debug[13:29:46,190]: ***** TreeItem getElements. id: zfpForm:memberSelectionDialog:memberSelectorTree:0. This: [object Object]
                warn[13:29:46,192]: ***** TreeSelection setSelection. item is null. ID: zfpForm:memberSelectionDialog:memberSelectorTree:3
                debug[13:29:46,193]: ***** Tree getNodeElements Input ID: zfpForm:memberSelectionDialog:memberSelectorTree:input. Input: [object HTMLInputElement]
                debug[13:29:46,193]: ***** TreeItem getElements. id: zfpForm:memberSelectionDialog:memberSelectorTree:3. This: [object Object]
                debug[13:29:46,195]: ***** Tree getNodeElements Input ID: zfpForm:memberSelectionDialog:memberSelectorTree:input. Input: [object HTMLInputElement]


                As you can see, the setSelection is being called BEFORE the getElements and getNodeElements. Which means that the code is attempting to use variables before they are initialized.

                Now I am not yet sure why the timing is off, but I am leaning towards a bug with code in Ajax4Jsf that uses code like "window.setTimeout(script, 50);" to evaluate the inline code in the page. If this is true that means that the tree only works if you are lucky enough to have the scripts run in the correct order. I will keep looking into this.

                Once I get enough information I will create a bug (blocker) for this issue as it causes the tree to be inoperable (not to mention any other A4j or RichFaces controls that depend on prototype code.

                • 5. Re: Tree selection stops working after 1-2 clicks
                  nbelaevski

                  Andrew,

                  Thank you for reporting! I'll investigate the problem you've described. Can you please post code sample causing tree to stop working? Thank you!

                  • 6. Re: Tree selection stops working after 1-2 clicks
                    andrew.rw.robinson

                    I tracked down the issue to when more than one node is updated per-request. I logged the bug and mentioned the simple fix.

                    http://jira.jboss.com/jira/browse/RF-50

                    • 7. Re: Tree selection stops working after 1-2 clicks
                      andrew.rw.robinson

                      I don't have any pre-packaged code, but I can tell you how to reproduce it.

                      Use a NodeSelectionEvent listener method in a backing bean, and then update a few nodes in that bean in the event.

                      Java code snippets:

                      public void onTreeNodeSelection(NodeSelectedEvent evt)
                      {
                       HtmlTree tree;
                       if (evt.getComponent() instanceof UITreeNode)
                       tree = (HtmlTree)evt.getComponent().getParent();
                       else
                       tree = (HtmlTree)evt.getComponent();
                      
                       TreeRowKey key = (TreeRowKey)tree.getRowKey();
                       Set keys = tree.getAjaxKeys();
                       if (keys == null)
                       {
                       keys = new HashSet();
                       tree.setAjaxKeys(keys);
                       }
                      
                       AjaxContext ajaxCtx = AjaxContext.getCurrentInstance();
                       FacesContext fctx = FacesContext.getCurrentInstance();
                       tree.setRowKey(null);
                       // Force more than one node to update here:
                       for (int i = 0; i < 5; i++)
                       {
                       ListRowKey dirtyKey = new ListRowKey(Integer.toString(i));
                       keys.add(dirtyKey);
                       tree.setRowKey(dirtyKey);
                       ajaxCtx.getAjaxAreasToRender().add(tree.getClientId(fctx));
                       }
                       tree.setRowKey(key);
                      }
                      

                      TreeNodeImpl rootNode = new TreeNodeImpl();
                      rootNode.setData("Root node");
                      for (int i = 0; i < 10; i++)
                      {
                       TreeNodeImpl child = new TreeNodeImpl();
                       String id = Integer.toString(i);
                       child.setData("Node: " + id);
                       rootNode.addChild(id, child);
                      }
                      


                      XHTML:
                      <rf:tree
                       id="testTree"
                       var="_data"
                       switchType="ajax"
                       ajaxSubmitSelection="true"
                       preserveModel="none"
                       binding="#{testTree}"
                       value="#{ajaxTreeTest.rootNode}"
                       nodeSelectListener="#{ajaxTreeTest.onTreeNodeSelection}"
                       nodeFace="node">
                       <rf:treeNode type="node">
                       #{_data}
                       </rf:treeNode>
                      </rf:tree>
                      


                      I didn't test this example, but it *should* re-produce the problem. What you want to have happen is the getNodeElements for a node that is not the previous select to execute before the node that was the previous selection. That way the "($(this.tree.input.value)).object" will be null (since AJAX just replaced this element in the page, but the prototype isn't bound to that element yet)

                      • 8. Re: Tree selection stops working after 1-2 clicks
                        nbelaevski

                        Hello Andrew!

                        Looks like the problem is caused by incorrect DOM structure inserted after AJAX request. I'll investigate the problem and will see what can be done to fix it.

                        • 9. Re: Tree selection stops working after 1-2 clicks
                          nbelaevski

                          Hello Andrew!

                          Thank you for the sample! The problem is fixed in trunk now.