O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using the poll component to display the current time

Let's display live time by polling server time for every second and display it using the poll component.

  1. Create poll.xhtml with a poll component to display currentTime as follows:
    <h:form>
      <p:outputLabel value="Current Time:" /> <p:outputLabel id="currentTime" value="#{serverTimeBean.time}"/>
      <p:poll interval="1" listener="#{serverTimeBean.updateTime()}" update="currentTime"/>
    </h:form>
  2. Create ServerTimeBean.java managed bean with the updateTime() method to set the currentTime value as follows:
    @ManagedBean @RequestScoped public class ServerTimeBean { private String time; public void setTime(String time) { this.time = time; } public String getTime() { return time; } public void ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required