6 Replies Latest reply on May 4, 2007 7:30 PM by Sergey Smirnov

    a4j:poll

    Pranav Vaidya Newbie

      Hello,

      I tried executing the code given for the sample poll on this site on my TOMCAT webserver.

      With a deployable WAR file, the code works fine.

      However, the exact same JSP and a similar backing bean run but the polling happens only once. The counter is only incremented once. The following is the JSP code and the backing bean.

      public class MyBean {
       private Integer counter;
      
       public MyBean() {
       }
      
       public Integer getCounter() {
       System.out.println(this.counter);
       return counter;
       }
      
       public void setCounter(Integer counter) {
       this.counter = counter;
       }
      
       public String incCounter() {
       counter++;
       return null;
       }
      
       public String resetCounter() {
       counter = 0;
       return null;
       }
      
      }


      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j" %>
      <html>
       <head>
       <title>A4j-poll. Example of use.</title>
       </head>
       <body>
       <f:view>
       <h:outputText value="Auto Counter:" />
       <h:outputText id="cnt" value="#{myBean.counter}" />
       <h:form>
       <a4j:poll id="picker" enabled="#{myBean.counter != 5}" action="#{myBean.incCounter}"
       reRender="picker, cnt, reset" interval="1000"/>
       <h:panelGroup id="reset" >
       <a4j:commandButton image="/images/counter.gif" reRender="picker,:cnt, reset"
       action="#{myBean.resetCounter}" rendered="#{myBean.counter == 5}"/>
       </h:panelGroup>
       </h:form>
       </f:view>
       </body>
      </html>


      And faces-config.xml is

      <?xml version="1.0"?>
      <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
      "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
      <faces-config>
       <managed-bean>
       <managed-bean-name>wBean</managed-bean-name>
       <managed-bean-class>WeatherLocationBean</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       <managed-property>
       <property-name>locations</property-name>
       <property-class>java.util.List</property-class>
       <list-entries/>
       </managed-property>
       <managed-property>
       <property-name>location</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>place</managed-bean-name>
       <managed-bean-class>Place</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       <managed-property>
       <property-name>icon</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       <managed-property>
       <property-name>id</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       <managed-property>
       <property-name>lat</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       <managed-property>
       <property-name>lng</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       <managed-property>
       <property-name>zoom</property-name>
       <property-class>int</property-class>
       <value/>
       </managed-property>
       <managed-property>
       <property-name>desc</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       <managed-property>
       <property-name>nameToDisplay</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>pcBean</managed-bean-name>
       <managed-bean-class>PointCollBean</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       <managed-property>
       <property-name>point</property-name>
       <property-class>java.util.ArrayList</property-class>
       <list-entries/>
       </managed-property>
       <managed-property>
       <property-name>currentId</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       <managed-property>
       <property-name>gmapKey</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
       </managed-property>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>myBean</managed-bean-name>
       <managed-bean-class>MyBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       <managed-property>
       <property-name>counter</property-name>
       <property-class>java.lang.Integer</property-class>
       <value>0</value>
       </managed-property>
       </managed-bean>
      </faces-config>


      I dont understand why the counter is only incrementing once. The first AJAX request if being processed. However, the next AJAX requests are not being sent to the server.

      Please Help !!
      Thanks and Regards,
      Pranav




        • 1. Re: a4j:poll
          Sergey Smirnov Master

          The code is OK. I guess, you use Ajax4jsf 1.1.0 . It was a bug there that caused such behavior. So, try the latest snapshot of 1.1.1:
          http://maven.exadel.com/org/ajax4jsf/ajax4jsf/1.1.1-SNAPSHOT/

          • 2. Re: a4j:poll
            Pranav Vaidya Newbie

            I tried the new version too but it gives a problem.

            I tried the older ajaxjar file which comes with the source and it works perfectly. However, the new JavaFaces depends on the new AJAX version.

            Hence either I have to use old AJAX jar file or not use the new RichFaces.

            The newer version of RichFaces depends of the the AJX which does not support polling.

            • 4. Re: a4j:poll
              Robert Weber Newbie

              I have experienced this issue also.

              In my project, I use a4j 1.1.1 and richfaces 3.0.1 (latest SNAPSHOT of each). It was necessary for me to put an a4j:poll component in a rich:modalPanel widget. However, it did not seem to be working. No matter what I tried, the a4j:poll component only seemed to poll the server once.

              Then, I downloaded and installed the example (a4j-poll-n-button), and it worked fine on initial deploy. Then, I plugged the a4j 1.1.1 JAR into the example, replacing the 1.1.0 that came with the example. The example stopped working.

              So I examined the WEB-INF/lib dir of the SNAPSHOT of the richfaces example application, and on a whim I started updating the libraries of the example a4j-poll-n-button app. Eventually it worked again.

              I attempted the same strategy with my own app. However, I did not meet with success.

              The a4j-poll-n-button app uses jsf 1.1 with JSP. I use jsf 1.2_04_b10 with facelets. I was under the impression that the JSF version does not particularly matter, and a4j is compatible with facelets, but since my application and the example a4j-poll-n-button only differ by those libs, I am currently unable to draw any further conclusion.

              I mean, the markup is certainly different...

               <rich:modalPanel minHeight="200" minWidth="450" height="200"
               width="500" zindex="2000" id="someDialog">
               <f:facet name="header">
               <h:outputText value="Are You Sure?" />
               </f:facet>
               <f:facet name="controls">
               <h:graphicImage value="/graphics/close.png" style="cursor:pointer"
               onclick="Richfaces.hideModalPanel('someDialog')" />
               </f:facet>
              
               <a4j:status id="myStatus" startText="Working" stopText="Idle"
               stopStyle="background-color: green; color: white;"
               startStyle="background-color: red; color: white;" />
               <h:outputText value="${someObject.currentStatus}" id="testing" />
               <h:form>
               <a4j:poll id="preActionChecker"
               enabled="#{!html$client$pages$admin.preActionFinished and html$client$pages$admin.preActionStarted}"
               action="#{html$client$pages$admin.checkPreAction}"
               reRender="preActionChecker,:testing,goodForm,badForm" interval="1000" limitToList="true" />
              
               <h:panelGroup id="goodForm">
               <a4j:region renderRegionOnly="false"
               rendered="#{someObject.currentStatus == 'good'}">
               <p>Are you sure you want to good?</p>
              
               <a class="buttonLink"
               href="javascript:Richfaces.hideModalPanel('someDialog')">No</a>
               <a4j:commandLink styleClass="buttonLink" value="Yes"
               action="#{html$client$pages$admin.goodAction}"
               reRender="itemTable">
               <a4j:actionparam name="activityId"
               value="#{someObject.activityNumber}" />
               </a4j:commandLink>
               </a4j:region>
               </h:panelGroup>
               <h:panelGroup id="badForm">
               <a4j:region renderRegionOnly="false"
               rendered="#{someObject.currentStatus == 'bad'}">
               <p>Something bad happen. Resolve?</p>
              
               <a class="buttonLink"
               href="javascript:Richfaces.hideModalPanel('someDialog')">No</a>
               <a4j:commandLink styleClass="buttonLink" value="Yes"
               action="#{html$client$pages$admin.badAction}
               reRender="itemTable">
               <a4j:actionparam name="activityId"
               value="#{someObject.activityNumber}" />
               </a4j:commandLink>
               </a4j:region>
               </h:panelGroup>
               </h:form>
               </rich:modalPanel>
              


              When this snippet renders, the status component changes state to indicate that a request is in process. Then, between 1 and 2 seconds later, the status component changes state to indicate that request processing has ceased. However, at that time, nothing seems to be re-rendered as expected.

              Maybe it is a matter of satisfying some dependency that I have failed to find? I thought I had been thorough, though...

              Note that the above is not my original code. I was so frustrated with the issue that I was starting to try arbitrary potential solutions, so maybe it would work if I took out some of the excess?

              • 5. Re: a4j:poll
                Pranav Vaidya Newbie

                Well, finally we gave up trying to use the entire richfaces. We got problems only when trying to use Drag and Drop components.

                So what we did is to download individual wars of the components we used. (We did not use Drag and Drop...so we were lucky there !!) and used only those tags. I am attaching the snippet relevant to you.

                <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
                <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                <%@ taglib uri="http://richfaces.ajax4jsf.org/gmap" prefix="gmap"%>
                <%@ taglib uri="http://richfaces.ajax4jsf.org/suggestionbox" prefix="rich"%>
                <%@ taglib uri="http://richfaces.ajax4jsf.org/dataTable" prefix="data"%>





                <f:view>
                <h:form id="counter">
                <a4j:region>
                <h:panelGrid columns="4" border="0" style="border: 1px solid black;">
                <a4j:poll id="picker" enabled="#{wBean.enablePoll}" action="#{wBean.updatePlaceCollectionBean}" reRender="picker, reset, resetErr" interval="1000" />
                <h:panelGroup id="reset" >
                <data:dataGrid columns="1" value="#{pcBean.point}" var="place" id="dgLocLinks" rendered="#{wBean.renderDataGrid == 1}">
                </data:dataGrid>
                </h:panelGroup>

                </h:panelGrid>
                </a4j:region>
                </h:form>
                </f:view>


                • 6. Re: a4j:poll
                  Sergey Smirnov Master

                   

                  "pranav_vaidya" wrote:
                  Well, finally we gave up trying to use the entire richfaces. We got problems only when trying to use Drag and Drop components.


                  I suggest, you are wrong here. The whole libs is just a concatenation of all components jar files without any functionality on top of them. You can use the set individual jar files for sure, however no difference if you have one common jar and use those three components.