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 – manually start and stop polling

We will now demonstrate how to start and stop polling using external triggers such as start and stop buttons using following steps:

  1. Create a form with a poll component and start/stop buttons to start and stop polling using following code:
    <h:form>
      <p:outputLabel value="Current Time:" /> <p:outputLabel id="currentTime" value="#{serverTimeBean.time}"/>
      <p:poll interval="1"  listener="#{serverTimeBean.updateTime()}" update="currentTime" widgetVar="currentTimePoller" autoStart="false"/> <br/>
      <p:button value="Start" onclick="currentTimePoller.start()" href="#" />
      <p:button value="Stop" onclick="currentTimePoller.stop()" href="#"/><br/>
    </h:form>

What just happened?

We have set the autoStart attribute to ...

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