4 Replies Latest reply on Mar 17, 2008 6:49 PM by Robert Kovacevic

    Multiple a4j:polls on one page

    Robert Kovacevic Newbie

      I have several areas on a page that should be refreshed on different intervals. The code looks like this:

      <a4j:region>
       <h:form>
       <a4j:poll id="poll" interval="5000" reRender="poll, shortPausePanel" limitToList="true"/>
       </h:form>
      </a4j:region>
      
      <a4j:region>
       <h:form>
       <a4j:poll id="pollTimer" enabled="#{pingManager.ping()}" interval="1000" reRender="pollTimer, timeText" limitToList="true"/>
       </h:form>
      </a4j:region>
      
      <a4j:outputPanel ajaxRendered="false">
      <h:outputText id="timeText" value="#{pingManager.time}"/>
      </a4j:outputPanel>
      
      <a4j:outputPanel ajaxRendered="false">
      <s:div id="shortPausePanel">
      ... some component that need updating ....
      </s:div>
      </a4j:outputPanel>
      

      Behaviour that I'm getting is that both areas are updated on every poll. I would like my "timeText" to be updated every second, and shortPausePanel every 5 seconds.
      Is this possible with poll, and if so, what am I doing wrong?

      (I'm using seam 2.0)

        • 1. Re: Multiple a4j:polls on one page
          Sergey Smirnov Master

          We have created a small project based on your code. It works just fine. So, probably, you miss something in your description or the problem is outside of RuchFaces

          • 2. Re: Multiple a4j:polls on one page
            Robert Kovacevic Newbie

            Thank you for the reply, but I don't see what else could it be. The project is just an eclipse generated seam 2.0 project, without any additional components or changes. Could you tell me what version of RichFaces did you use, and are you sure "shortPanelPause" didn't update every 1 second?

            Here's my whole page (it's little rearanged, but the behaviour stayed the same):

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
             xmlns:s="http://jboss.com/products/seam/taglib"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml"
             xmlns:a4j="http://richfaces.org/a4j">
            
             <ui:define name="body">
            
            
             <h:messages id="messages" globalOnly="true" styleClass="message" />
            
             <rich:panel id="panel">
             <a4j:region>
             <h:form>
             <a4j:poll id="pollTimer" enabled="#{pingManager.ping()}"
             interval="1000" reRender="pollTimer, timeText" limitToList="true" />
             </h:form>
             <f:facet name="header">
             <h:outputText id="timeText" value="#{pingManager.time}" />
             </f:facet>
             </a4j:region>
             <h2><h:outputText id="skill"
             value="Odjel: #{userManager.getUser().skill.name}" /></h2>
            
            
             <rich:separator />
            
             <h3><h:outputText value="Velika pauza" /></h3>
            
             <a4j:form id="longPauseForm"
             rendered="#{empty longPauseManager.longPauseSlot}">
             <h:selectOneMenu value="#{longPauseManager.longPauseSlot}">
             <s:selectItems value="#{longPauseSlots}" var="slot"
             label="#{slot.startHour}:#{slot.startMinute} - #{slot.stopHour}:#{slot.stopMinute}" />
             <s:convertEntity />
             </h:selectOneMenu>
             <h:commandButton action="#{longPauseManager.selectLongPauseSlot}"
             value="Odaberi" />
             </a4j:form>
            
             <h:outputText value="Vasa velika pauza je zakazana za: "
             rendered="#{not empty longPauseManager.longPauseSlot}" />
             <h:outputText
             value="#{longPauseManager.longPauseSlot.startHour}:#{longPauseManager.longPauseSlot.startMinute} - #{longPauseManager.longPauseSlot.stopHour}:#{longPauseManager.longPauseSlot.stopMinute}"
             rendered="#{not empty longPauseManager.longPauseSlot}" />
             <h:form>
             <h:commandButton action="#{longPauseManager.cancelLongPauseSlot}"
             value="Otkazi"
             rendered="#{not empty longPauseManager.longPauseSlot}" />
             </h:form>
            
             <rich:separator />
            
             <h3><h:outputText value="Mala pauza" /></h3>
             <a4j:region>
             <h:form>
             <a4j:poll id="poll" interval="5000"
             reRender="poll, skill, shortPausePanel, longPauseForm"
             limitToList="true" />
             </h:form>
             <s:div id="shortPausePanel">
            
             <h:outputText value="Korisnici trenutno na maloj pauzi: " />
             <h:dataTable value="#{pauseManager.getShortPauses()}"
             var="shortPause">
             <h:column>
             #{shortPause.user.username}
             </h:column>
             <h:column>
             #{shortPause.startTime}
             </h:column>
             </h:dataTable>
            
             <h:outputText value="Korisnici u redu cekanja: " />
             <h:dataTable value="#{pauseManager.getQuenes()}" var="quene">
             <h:column>
             #{quene.user.username}
             </h:column>
             </h:dataTable>
            
             <h:form rendered="#{not pauseManager.isOnPause()}">
             <h:commandButton action="#{pauseManager.requestPause}"
             value="Zatrazi malu" rendered="#{not pauseManager.isOnQuene()}" />
             </h:form>
            
             <h:form rendered="#{pauseManager.isOnQuene()}">
             <h:commandButton action="#{pauseManager.removeFromQuene()}"
             value="Otkazi malu" />
             </h:form>
            
             <h:form rendered="#{pauseManager.isPauseAvailable()}">
             <h:commandButton action="#{pauseManager.goOnPause()}"
             value="Odoh na pauzu" />
             </h:form>
            
             <h:form rendered="#{pauseManager.isOnPause()}">
             <h:commandButton action="#{pauseManager.endPause()}"
             value="Vratih se" />
             </h:form>
            
             </s:div>
             </a4j:region>
             </rich:panel>
            
             </ui:define>
            </ui:composition>
            

            Here's the logger output for pauseManager.isPauseAvailable():
            21:38:10,500 INFO [PauseManagerBean] b: enter isPauseAvailable()
            21:38:11,671 INFO [PauseManagerBean] b: enter isPauseAvailable()
            21:38:12,859 INFO [PauseManagerBean] b: enter isPauseAvailable()
            21:38:13,593 INFO [PauseManagerBean] b: enter isPauseAvailable()
            21:38:14,046 INFO [PauseManagerBean] b: enter isPauseAvailable()
            21:38:15,218 INFO [PauseManagerBean] b: enter isPauseAvailable()
            

            As you can see, it's called every second, instead every 5 seconds, as specified in poll interval.

            • 3. Re: Multiple a4j:polls on one page
              Alexander Smirnov Master

              We are sure about separate updates, so getTime() in the backing bean simple returns the current System time. Different time in the output text mean different updates.

              Invoking a pauseManager.isPauseAvailable() does not mean an ajax rendering. It is binded to the form "rendered" attribute.
              JSF framework checks value for a "rendered" attribute not only during the rendering, but at the decode/validate/update lifecycle phases, in the "invokeOnComponent" calls, etc.

              • 4. Re: Multiple a4j:polls on one page
                Robert Kovacevic Newbie

                I get it now :) You are absolutely correct. Thank you both for your help!