7 Replies Latest reply on Feb 25, 2010 10:34 AM by nimo stephan

    Cancelling an a4j:poll

    Travers Naran Newbie

      I have a RichFaces tabPanel set, and on one of the tabs, a poll.  When the user changes tabs (using the 'ajax' switching method), the poll will run more time (on schedule) then stop running.  I want to cancel that poll when I switch tabs.  I figured just changing tabs would do it because the poll is defined inside the <rich:tab> ... </rich:tab> and when changing tabs, the poll would not be rendered and the javascript timed & sent poll request would be ignored, but it is not.


      Any suggestions?  Thanks in advance, everybody!

        • 1. Re: Cancelling an a4j:poll
          Benjamin Kersten Newbie

          The poll once actived causes a JS based timer to send AJAX requests continously (concurrent to user AJAX requests). A tab switch (ajax switch mode) does not destroy the JS timer, but additional AJAX requests might be send (by the poll) before your user AJAX request (tab switch) is completed. This might cause a few more poll-ajax-requests after tab change or concurrent to it resp. (depending on interval settings and response time of tab switch). I think this is still the official/recommended way to stop polling (i.e. set pollFlag to false with tab change and reRender the poll-component).


          If u need to stop polling immediately with the tab change u might want to consider to call A4J.AJAX.StopPolling( pollComponentClientId ) to unregister the timer per JS. This is probably not the "official way", i.e. i don't know about future JS API changes or compatibility to your code, but it worked in the sample below:


          <a4j:region id="region">
                 <h:form id="pollForm">
                     <a4j:poll id="poll" interval="500" enabled="#{TestBean.pollEnabled}"
                         reRender="poll,panel" />
               <rich:tabPanel switchType="ajax" ontabchange="A4J.AJAX.StopPoll('pollForm:poll');">
                    <rich:tab label="tabPoll">
                        <a4j:outputPanel id="panel">
                                 <h:outputText id="pollValue" value="#{TestBean.currentDate}" />
                    <rich:tab label="tab2nd">
                         <h:outputText value="test"/>
               <a4j:commandButton style="width:120px" id="control"
                            value="#{TestBean.pollEnabled?'Stop':'Start'} Polling"
                            reRender="control, poll, panel">
                            <a4j:actionparam name="polling" value="#{!TestBean.pollEnabled}"
                                assignTo="#{TestBean.pollEnabled}" />


          In addititon to that: i think it is not recommended to put the poll component into a form of the tab panel together with different components, as all values will be transmitted with each poll (cp. hints at http://livedemo.exadel.com/richfaces-demo/richfaces/poll.jsf;c=poll&tab=usage ). Instead, usage of a seperate form/region as above should be preferable.

          1 of 1 people found this helpful
          • 2. Re: Cancelling an a4j:poll
            Ilya Shaikovsky Master

            thanks! It's could be used but undocumented so added the point to FAQ. http://community.jboss.org/wiki/AjaxCoreComponents

            • 3. Re: Cancelling an a4j:poll
              nimo stephan Master

              So I assume, that there also exists the JS-Method:



              Where can I find all the Java-Script A4J-or Richfaces Methods such as







              Does Richfaces has a Java-Script-API ?
              Where can I find it?


              If not, where can I find the JS-sources (in rf-api, rf-impl or rf-ui), so I can grab the methods out of it?

              • 4. Re: Cancelling an a4j:poll
                Ilya Shaikovsky Master

                Yes start methods like you mentioned also exist.


                Unfortunatelly we didn't caried about public JS API from the beggining. So the components created since 3.2.x - has them in documentation and older components not. So if you can't find api in documentation - unfortunatelly you will need to check js on your own. Them could be find at:








                3.3.x branch will not be changed significantly in the future as it's under stabilization works only so you could safelly use any of the components methods which need.


                And good news - we will care about that in 4.x from the beggining for every component.

                • 5. Re: Cancelling an a4j:poll
                  nimo stephan Master

                  I am looking forward in using RF 4



                  I click "A4J.AJAX.StopPoll" - it stops polling.

                  After it stops, I click "A4J.AJAX.StartPoll" but it does not start the poll again, why?




                  <h:form id="form_view_progress">

                     <a4j:poll id="poll"













                  <a4j:commandButton value="start poll" onclick="A4J.AJAX.StartPoll('my_form:poll');"/>

                  <a4j:commandButton value="stop poll" onclick="A4J.AJAX.StopPoll('my_form:poll');"/>





                  What is the name of the *.js-script?


                  Cannot find a "poll.js"

                  in richfaces-ui-3.3.3-SNAPSHOT.jar\org\richfaces\renderkit\html\script\ or


                  • 6. Re: Cancelling an a4j:poll
                    Ilya Shaikovsky Master

                    seems I just looked to some wrong place found some start functions and decided that them are defined for poll unfortunatelly there are no such methods. But if you need to just start polling after tab actually changed - just reRender it from tab so it will be re-initialized and started.

                    • 7. Re: Cancelling an a4j:poll
                      nimo stephan Master
                      okay thanks, have done that.