component in Visualforce Page
The <apex:actionPoller> component is a special type of component that works based on time and interval. It is a timer used for sending an AJAX request to the server according to the specified time interval.
The <apex:actionPoller> component should be used within the region it acts upon. If we want to use the <apex:actionPoller> with the <apex: actionRegion>, the <apex:actionPoller> should be used within the <apex:actionRegion> component.
In order to use the <apex:actionPoller> component, we have to go through the following consideration:
- The action method should be light-weighted, which we define in the <apex:actionPoller>. In the action method, we need to avoid using DML, external service calls, and other resource-intensive operations.
- The connection is regularly refreshed by the <apex:actionPoller> component, so we must keep the login session alive. Due to inactivity, the apex page with the <apex:actionPoller> would not timeout.
- It resets itself when the <apex:actionPoller> component is ever re-rendered as the result of another action.
- For defining the time interval to server requests from the apex controller, we can't use the Visualforce expression.
- We need to avoid using actionPoller with enhanced lists.
The <apex:actionPoller> component has the following attributes:
The action attribute is of type ApexPages.Action that defines the action method. The action method is invoked by the periodic AJAX update request from the component. The page simply refreshes when there is no action method defined in this component.
The enabled attribute is of type Boolean that is used to specify the active and inactiveness of the <apex:actionPoller> component. By default, its value is set to true.
The id attribute is of type string that is a unique identifier allowing this component to be referenced by other components on the page.
The interval attribute is of type Integer that is used to specify the time interval between AJAX update requests in seconds. The value of this attribute must be 5 seconds or greater. By default, its value is set to 60 seconds.
The rendered attribute is of type Boolean that is used to specify whether the current component is rendered on the page or not. By default, its value is set to true.
When we want to redraw one or more components on the page after receiving the result of an AJAX update request by the client, we use this component to specify the Ids of those components.
The status attribute is of type string that is used for specifying the id of the component responsible for displaying the status of an AJAX update request.
The timeout attribute is used for defining the amount of time before an AJAX update request should timeout.
Let's take an example to understand how we can use the <apex:actionPoller> component in VF: