Wednesday, September 3, 2014

What is actionpoller in visualforce?

What is actionpoller in visualforce?


Action poller acts as a timer in visualforce page. It is used to send an AJAX request to the server depending on the time interval (time interval has to be specified or else it defaults to 60 seconds).

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 5 seconds.

In the following example action poller calls the method "CounterMethod" every 5 seconds where the variable "seconds" counter is updated. Rerender attribute refreshes the page block hence showing the updated value of variable "seconds".

Controller Class:
Public with sharing class actionpollerDemoController {
Public  Integer seconds{get;set;}
  Public actionpollerDemoController(){
   seconds = 0;
  }
  Public void CounterMethod(){
    seconds = seconds + 5;
  }
}

Visualforce Page:

<apex:page controller="actionpollerDemoController">
    <apex:form >
        <apex:pageBlock id="pgplck">
              <apex:actionPoller action="{!CounterMethod}" reRender="pgplck" interval="5"/>
                      {!seconds } seconds since the action poller was called !!
         </apex:pageBlock>
      </apex:form>
</apex:page>


Output :

save image


Time out can also be specified as an attribute in action poller. Once the time out point is reached it stops making AJAX callout to the server and controller method is no more called.




1 comments:

nick jones said...

thanks for sharing..
Wireless Access Points

Post a Comment

 
| ,