10 Replies Latest reply on Oct 30, 2009 6:50 AM by bp2s

    a4j:poll server date clock not updating

    bp2s

      Hi - easy one I hope:

      Cut and pasted code from the web nice and easy - all I'm after is a clock from the server output on the header of my web app. The bean loads fine no errors (built in eclipse/ant/tomcat all the latest by the date of this post), and outputs the date in the header, but it's not updating. I've been on at it for a day (waste?) and it's still not working. Any help enormously appreciated.

      i don't think it's cos i'm referencing taglibs on the web and i'm behind a proxy as it'd either error or prompt me and i'm getting silence.
      m

      index.jsp:

      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <!-- RichFaces tag library declaration -->
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      
      
      <snip>
      
       <rich:toolBarGroup>
       <a4j:region>
       <h:form>
       <a4j:poll id="poll" interval="1000" enabled="true" reRender="serverDate" />
       </h:form>
       </a4j:region>
      
       <h:form>
       <h:panelGrid columns="1" width="100%" id="title">
       <span id="titleText">MY TITLE  </span>
       <h:outputText id="serverDate" value="#{Welcome.dateTime}" />
       </h:panelGrid>
       </h:form>
       </rich:toolBarGroup>
      


      and my Welcome.java code:

      
      package myPkg;
      
      import java.util.*;
      import java.text.DateFormatSymbols;
      import javax.faces.model.SelectItem;
      
      public class Welcome {
       private String name="";
       private String dateTime="";
       private List nodes;
      
       public String getDateTime() {
       Calendar cal = new GregorianCalendar();
       String[] monthName = { "January", "February", "March", "April", "May", "June", "July",
       "August", "September", "October", "November", "December" };
       String[] weekdays = new DateFormatSymbols().getWeekdays();
      
       int year = cal.get(Calendar.YEAR);
       String date = String.format("%02d", cal.get(Calendar.DAY_OF_MONTH));
       String hr = String.format("%02d", cal.get(Calendar.HOUR_OF_DAY));
       String min = String.format("%02d", cal.get(Calendar.MINUTE));
       String sec = String.format("%02d", cal.get(Calendar.SECOND));
      
      
       dateTime = weekdays[cal.get(Calendar.DAY_OF_WEEK)] + " " + monthName[cal.get(Calendar.MONTH)] + " " + date + " " + year + " " + hr + ":" + min + ":" + sec;
       return dateTime;
       }
      }
      
      


        • 1. Re: a4j:poll server date clock not updating
          thomasgo

          The richfaces doc. contains this line:

          <a4j:poll id="poll" interval="1000" enabled="#{userBean.pollEnabled}" reRender="poll,grid"/>

          and reading the text I assume you need to rerender poll, too.

          • 2. Re: a4j:poll server date clock not updating
            bp2s

            Thanks for getting back to my ThomasGo.

            Yes, the text I posted was after many many tries with different permutations. With this:

            <rich:toolBarGroup>
             <a4j:region>
             <h:form>
             <a4j:poll id="poll" interval="1000" enabled="true" reRender="poll,grid" />
             </h:form>
             </a4j:region>
            
             <h:form>
             <h:panelGrid columns="1" width="100%" id="grid">
             <span id="titleText">PRISM CONFIGURATOR  </span>
             <h:outputText id="datum" value="#{Welcome.dateTime}" />
             </h:panelGrid>
             </h:form>
            </rich:toolBarGroup>
            
            


            it's still not working.

            Incidentally,

            • 3. Re: a4j:poll server date clock not updating
              bp2s

              Please ignore string 'Incidentally,' in the last post.

              • 4. Re: a4j:poll server date clock not updating
                ilya_shaikovsky

                any exceptions in server log? also check a4j:log for any client side errors.

                • 5. Re: a4j:poll server date clock not updating
                  ilya_shaikovsky

                  and b.t.w. poll rerendering at demosite used only because it's becames disabled after a minute of working by design.

                  • 6. Re: a4j:poll server date clock not updating
                    bp2s

                    I get the log out through Eclipse and there is nothing written to it relevant to this problem/ajax.

                    Cheers for looking at this.

                    • 7. Re: a4j:poll server date clock not updating
                      bp2s

                      re your btw - i'd taken the commandButton code out as i wanted the clock to continue all the time.

                      • 8. Re: a4j:poll server date clock not updating
                        bp2s

                        I've scoured the net again and tried a few more things but I still cannot get the clock to update. Further, as I now have a SelectOneMenu which causes an ajaxian update of further information, I need to fix this if poss.

                        I've installed phaseTracker and a4j:log.

                        phaseTracker is not showing repeated requests to the server. The a4j:log output when the page loads is:

                        debug[17:54:19,409]: Query preparation for form 'j_id_jsp_920730595_3:j_id_jsp_920730595_9' requested

                        Just as though no ajax request is being made to the server at periods. I'm quite confused now.

                        Where should I be looking to check what might be going on? Any help massively appreciated.

                        M

                        • 9. Re: a4j:poll server date clock not updating
                          nbelaevski

                          Hi,

                          I guess some of surrounding elements can be the reason - please try to leave only

                          <a4j:region>
                           <h:form>
                           <a4j:poll id="poll" interval="1000" enabled="true" reRender="serverDate" />
                           </h:form>
                           </a4j:region>
                          
                           <h:form>
                           <h:panelGrid columns="1" width="100%" id="title">
                           <span id="titleText">MY TITLE  </span>
                           <h:outputText id="serverDate" value="#{Welcome.dateTime}" />
                           </h:panelGrid>
                           </h:form>

                          and check.

                          • 10. Re: a4j:poll server date clock not updating
                            bp2s

                            nbelaevski - fixed, many thanks.

                            As I was building the page, I brought in a rich:toolbar and it broke it at that point.

                            I've separated the a4j:region and the h:form so the form is in the rich:toolbar but the a4j is not. functionality now works but also the object renders on the correct part of the page - in the header, where the clock should be:

                            
                            <a4j:region>
                             <h:form>
                             <a4j:poll id="poll" interval="1000" enabled="true"
                             reRender="poll,grid" />
                             </h:form>
                            </a4j:region>
                            
                            <f:facet name="header">
                             <h:form>
                             <rich:toolBar height="55" itemSeparator="line">
                             <rich:toolBarGroup>
                             <h:graphicImage id="Logo" value="/img/LBYK.gif"
                             alt="Logo" />   
                             </rich:toolBarGroup>
                            
                             <rich:toolBarGroup>
                             <h:form>
                             <h:panelGrid columns="1" width="100%" id="grid">
                             <span id="titleText">CONFIG  </span>
                             <h:outputText id="datum" value="#{Welcome.dateTime}" />
                             </h:panelGrid>
                             </h:form>
                             </rich:toolBarGroup>
                            


                            I didn't see that I needed to make this kind of separation in the documentation...
                            m