Action Poller in Visualforce Page

Action poller acts as a timer in visualforce page. It sends an AJAX request to the server according to a time interval (time interval has to be specified or else it defaults to 60 seconds). Each request can result in a full or partial page update.
In this article I will demonstrate how to use actionpoller in visualforce page.

  • In the action attribute a controller method gets called. The method gets called with a frequency defined by the interval attribute which has to be greater than or equal to 5 seconds.
  • Time out can also be specified as an attribute in actionpoller. Once the time out point is reached it stops making AJAX callout to the server and controller method is no more called.

Create Apex class with following code:

Public with sharing class TestActionPoller
    Public  Integer Total{get;set;}
    Public TestActionPoller()
        Total = 0;
    Public void CountMethod()

Now create the Visualforce page:

<apex:page controller="TestActionPoller">
<apex:outputtext id="idCount" value="Increase in every 5 seconds: {!Total}">
<apex:actionpoller action="{!CountMethod}" interval="5" rerender="idCount">

In above visualforce page Action poller calls the method “CountMethod” every 5 seconds where the variable “Total” is updated. Rerender attribute refreshes the page block hence showing the updated value of variable “Total”.


Leave a Reply