Tuesday, November 29, 2016

actionPoller Tag in Visualforce

actionPoller tag specifies a timer that sends an AJAX update request at specified interval.
Minimum interval time to refresh is 5 sec.

Here in this post i am providing a simple example to explain about actionPoller. I am calling a simple method from controller to display Date & TIme and recalling that method by using actionPoller tag to change the time for every 5 sesc. See the below code to understand how actionPoller will work.


Page:

<apex:page controller="actionpollerDemoController">
    <apex:form >
        <apex:pageBlock id="pb">
               <apex:actionPoller action="{!dateTimeMethod}" reRender="pb" interval="5"/>
                Hello!!! Date and Time: {!dateAndTime}
               <p>Note: Time will refresh fror every 5 sec.</p>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Controller:

Public with sharing class actionpollerDemoController {
        Public DateTime dateAndTime{get;set;}
        Public void dateTimeMethod(){
            dateAndTime = System.now();
        }
}

OutPut: In below Image Date and Time will refresh for every 5 secs



No comments:

Post a Comment