8 Replies Latest reply on May 19, 2017 6:10 AM by michpetrov

    rich:tree, onToggle not trigerred

    chupacabras

      I am struggling to make "ontoggle" event work on "rich:treeNode" or "rich:tree".

      "onbeforetoggle" works just fine.

      I am using Richfaces 4.5.17:

      richfaces-a4j-4.5.17.Final.jar
      richfaces-core-4.5.17.Final.jar
      richfaces-page-fragments-4.5.17.Final.jar
      richfaces-rich-4.5.17.Final.jar
      

       

      This is the code of XHTML:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">
      
      <h:head>
      </h:head>
      <h:body>
          <h:form>
                  <rich:tree id="tree" onnodetoggle="alert(22);" onbeforeselectionchange="alert(1);" onselectionchange="alert(2);" selectionChangeListener="#{structureBean.selectionChanged}" nodeType="#{node.type}" var="node" value="#{structureBean.rootNodes}" toggleType="ajax" selectionType="ajax" >
                      <rich:treeNode type="department" iconLeaf="#{node.icon}" iconExpanded="#{node.icon}" iconCollapsed="#{node.icon}" expanded="#{node.expanded}" onbeforetoggle="alert(4); return true;" ontoggle="alert(5);">
                          <a4j:outputPanel>
                                  <h:outputText value="#{node.data.universalTitle}" />
                          </a4j:outputPanel>
                      </rich:treeNode>
                  </rich:tree>
          </h:form>
      </h:body>
      </html>
      

       

      Page looks like this:

      2017-05-18 16_45_50-Mozilla Firefox.png

      When I click "+" icon, a get alert "4", but alert "5" and alert "22" are not triggered.

       

      The HTML source code of that page contains this code, those alerts are there. But not triggered.

      <script type="text/javascript">
      new RichFaces.ui.Tree("j_idt4:tree",{"toggleType":"ajax","selectionType":"ajax","ajaxSubmitFunction":"RichFaces.ajax(source,event,{\"incId\":\"1\",\"clientParameters\":params,\"complete\":complete} )","onbeforeselectionchange":"alert(1);","onselectionchange":"alert(2);","clientEventHandlers":{":0:j_idt5":{"th":"return jsf.util.chain(this,event,\"alert(5);\",\"alert(22);\")","bth":"alert(4); return true;"} ,":1:j_idt5":{"th":"return jsf.util.chain(this,event,\"alert(5);\",\"alert(22);\")","bth":"alert(4); return true;"} } } );
      </script>
      

       

      How to make it work? Where is the problem?

        • 1. Re: rich:tree, onToggle not trigerred
          michpetrov

          Are you sure it's not your browser? Try console.log instead of the alerts.

          • 2. Re: rich:tree, onToggle not trigerred
            chupacabras

            I am pretty sure it's not my browser. I tried Firefox, IE11, Chrome. There is no error/exception in browser's debugging console.

             

            I replaced alerts with console.log. It did not help. Console shows only "4" text.

            Values "5" and "22" are not there. So ontoggle is not triggered.

             

            2017-05-18 17_57_36-Clipboard.png

            • 3. Re: rich:tree, onToggle not trigerred
              michpetrov

              Well, everything works fine when I try to replicate it. The toggle events are triggered by the AJAX response (you should see something like "RichFaces.ui.TreeNode.emitToggleEvent("j_idt4:tree:0.4.0.0:j_idt5");" it won't trigger if it cannot find the node but that shouldn't be the case here.

              • 4. Re: rich:tree, onToggle not trigerred
                chupacabras

                There is no element "j_idt4:tree:0.4.0.0:j_idt5" in that page.

                 

                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE html>
                <html xmlns="http://www.w3.org/1999/xhtml">
                    <head id="j_idt2">
                        <link type="text/css" rel="stylesheet" href="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/skinning.ecss?db=eAG7dPvZfwAIqAOT" />
                        <script type="text/javascript" src="/app1/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&amp;stage=Development"/>
                        <script type="text/javascript" src="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/jquery.js"/>
                        <script type="text/javascript" src="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/richfaces.js"/>
                        <script type="text/javascript" src="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/richfaces-queue.js"/>
                        <script type="text/javascript" src="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/richfaces-base-component.js"/>
                        <script type="text/javascript" src="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/richfaces-event.js"/>
                        <script type="text/javascript" src="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/tree.js"/>
                        <link type="text/css" rel="stylesheet" href="/app1/org.richfaces.resources/javax.faces.resource/org.richfaces/tree.ecss?db=eAG7dPvZfwAIqAOT" />
                    </head>
                    <body>
                        <form id="j_idt4" name="j_idt4" method="post" action="/app1/secured/organization/structure/b.xhtml" enctype="application/x-www-form-urlencoded">
                            <input type="hidden" name="j_idt4" value="j_idt4" />
                            <div class="rf-tr" id="j_idt4:tree">
                                <div class="rf-tr-nd rf-tr-nd-lf" id="j_idt4:tree:0:j_idt5">
                                    <div class="rf-trn">
                                        <span class="rf-trn-hnd-lf rf-trn-hnd"/>
                                        <span class="rf-trn-cnt">
                                            <img class="rf-trn-ico-lf rf-trn-ico rf-trn-ico-cst" alt="" src="/app1/resource/skins/standard/images/icon16/building-low.png" />
                                            <span class="rf-trn-lbl">
                                                <span id="j_idt4:tree:0:j_idt6">utvar1</span>
                                            </span>
                                        </span>
                                    </div>
                                </div>
                                <div class="rf-tr-nd rf-tr-nd-exp" id="j_idt4:tree:1:j_idt5">
                                    <div class="rf-trn">
                                        <span class="rf-trn-hnd-exp rf-trn-hnd"/>
                                        <span class="rf-trn-cnt">
                                            <img class="rf-trn-ico-exp rf-trn-ico rf-trn-ico-cst" alt="" src="/app1/resource/skins/standard/images/icon16/building-low.png" />
                                            <span class="rf-trn-lbl">
                                                <span id="j_idt4:tree:1:j_idt6">utvar2</span>
                                            </span>
                                        </span>
                                    </div>
                                    <div class="rf-tr-nd rf-tr-nd-lf" id="j_idt4:tree:1.0:j_idt5">
                                        <div class="rf-trn">
                                            <span class="rf-trn-hnd-lf rf-trn-hnd"/>
                                            <span class="rf-trn-cnt">
                                                <img class="rf-trn-ico-lf rf-trn-ico rf-trn-ico-cst" alt="" src="/app1/resource/skins/standard/images/icon16/building-low.png" />
                                                <span class="rf-trn-lbl">
                                                    <span id="j_idt4:tree:1.0:j_idt6">utvar3</span>
                                                </span>
                                            </span>
                                        </div>
                                    </div>
                                </div>
                                <input type="hidden" name="j_idt4:tree__SELECTION_STATE" id="j_idt4:tree__SELECTION_STATE" class="rf-tr-sel-inp" value="" />
                                <script type="text/javascript">new RichFaces.ui.Tree("j_idt4:tree",{"toggleType":"ajax","selectionType":"ajax","ajaxSubmitFunction":"RichFaces.ajax(source,event,{\"incId\":\"1\",\"clientParameters\":params,\"complete\":complete} )","onbeforeselectionchange":"console.log('1');","onselectionchange":"console.log('2');","clientEventHandlers":{":0:j_idt5":{"th":"return jsf.util.chain(this,event,\"console.log('5');\",\"console.log('22');\")","bth":"console.log('4');"} ,":1:j_idt5":{"th":"return jsf.util.chain(this,event,\"console.log('5');\",\"console.log('22');\")","bth":"console.log('4');"} ,":1.0:j_idt5":{"th":"return jsf.util.chain(this,event,\"console.log('5');\",\"console.log('22');\")","bth":"console.log('4');"} } } );</script>
                            </div>
                            <input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="1809762066624785631:-2577075702399804137" autocomplete="off" />
                        </form>
                    </body>
                </html>
                
                • 5. Re: rich:tree, onToggle not trigerred
                  chupacabras

                  The function you mentioned is not being called. I set breakpoint there (in tree.js) and it is not being called:

                   

                     rf.ui.TreeNode.emitToggleEvent = function(nodeId) {
                          var node = document.getElementById(nodeId);
                          if (!node) {
                              return;
                          }
                  
                          rf.component(node).__fireToggleEvent();
                      };
                  
                  • 6. Re: rich:tree, onToggle not trigerred
                    michpetrov

                    Juraj Lonc wrote:

                     

                    There is no element "j_idt4:tree:0.4.0.0:j_idt5" in that page.

                    Of course not, the id is from my local example. Can you show the response after you toggle a node? It should contain a <complete> tag.

                    • 7. Re: rich:tree, onToggle not trigerred
                      chupacabras

                      When I click on that "+" sign, this request is going to the server:

                       

                      j_idt4=j_idt4&j_idt4%3Atree__SELECTION_STATE=&javax.faces.ViewState=2155198868007617977%3A2631413778860331065&javax.faces.source=j_idt4%3Atree%3A1%3Aj_idt5&javax.faces.partial.execute=j_idt4%3Atree%3A1%3Aj_idt5%20%40component&javax.faces.partial.render=%40component&j_idt4%3Atree%3A1%3Aj_idt5__NEW_NODE_TOGGLE_STATE=true&j_idt4%3Atree%3A1%3Aj_idt5__TRIGGER_NODE_AJAX_UPDATE=true&org.richfaces.ajax.component=j_idt4%3Atree%3A1%3Aj_idt5&j_idt4%3Atree%3A1%3Aj_idt5=j_idt4%3Atree%3A1%3Aj_idt5&rfExt=null&AJAX%3AEVENTS_COUNT=1&javax.faces.partial.ajax=true
                      

                       

                      and this response returns from server:

                       

                      <?xml version='1.0' encoding='UTF-8'?>
                      <partial-response id="j_id1">
                          <changes>
                              <update id="j_idt4:tree:1:j_idt5">
                                  <![CDATA[<div class="rf-tr-nd rf-tr-nd-exp" id="j_idt4:tree:1:j_idt5"><div class="rf-trn"><span class="rf-trn-hnd-exp rf-trn-hnd"></span><span class="rf-trn-cnt"><img class="rf-trn-ico-exp rf-trn-ico rf-trn-ico-cst" alt="" src="/app1/resource/skins/standard/images/icon16/building-low.png" /><span class="rf-trn-lbl"><span id="j_idt4:tree:1:j_idt6">utvar2</span></span></span></div><div class="rf-tr-nd rf-tr-nd-lf" id="j_idt4:tree:1.0:j_idt5"><div class="rf-trn"><span class="rf-trn-hnd-lf rf-trn-hnd"></span><span class="rf-trn-cnt"><img class="rf-trn-ico-lf rf-trn-ico rf-trn-ico-cst" alt="" src="/app1/resource/skins/standard/images/icon16/building-low.png" /><span class="rf-trn-lbl"><span id="j_idt4:tree:1.0:j_idt6">utvar3</span></span></span></div></div></div>]]>
                              </update>
                              <eval>
                                  <![CDATA[RichFaces.ui.TreeNode.initNodeByAjax("j_idt4:tree:1:j_idt5",{"clientEventHandlers":{":1:j_idt5":{"th":"return jsf.util.chain(this,event,\"console.log('5');\",\"console.log('22');\")","bth":"console.log('4');"} ,":1.0:j_idt5":{"th":"return jsf.util.chain(this,event,\"console.log('5');\",\"console.log('22');\")","bth":"console.log('4');"} } } )]]>
                              </eval>
                              <update id="j_id1:javax.faces.ViewState:0">
                                  <![CDATA[2155198868007617977:2631413778860331065]]>
                              </update>
                          </changes>
                      </partial-response>
                      
                      • 8. Re: rich:tree, onToggle not trigerred
                        michpetrov

                        Yeah, there should more than that. Can you share a Short, Self Contained, Correct Example?