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

    a4j:poll server date clock not updating

    mark lewis Newbie

      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;
       }
      }