### Create new RichFaces Documentation Jira issue

Summary
255 characters left
Description
Environment
This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.org Community Documentation

- Prev
- Next

### 6.1.9. < a4j:poll > available since 3.0.0

expand all

#### 6.1.9.1. Description

The <a4j:poll> component allows periodical sending of Ajax requests to a server and is used for a page updating according to a specified time interval.

Table 6.16. a4j : poll attributes

Attribute Name | Description
--- | ---
action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by you, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property
actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingle | Limits JSF tree processing (decoding, conversion, validation and model updating) only to a component that sends the request. Boolean
binding | JSF: The attribute takes a value-binding expression for a component property of a backing bean
bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
enabled | Enables/disables polling. Default value is "true".
eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.)
focus | ID of an element to set focus after request is completed on client side
id | JSF: Every component may have a unique id that is automatically created if omitted
ignoreDupResponses | Attribute allows to ignore an Ajax Response produced by a request if the newest 'similar' request is in a queue already. ignoreDupResponses="true" does not cancel the request while it is processed on the server, but just allows to avoid unnecessary updates on the client side if the response isn't actual now
immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase
interval | Interval (in ms) for call poll requests. Default value is "1000"ms (1 second).
limitToList | If "true", then of all AJAX-rendered on the page components only those will be updated, which ID's are passed to the "reRender" attribute of the describable component. "false"-the default value-means that all components with ajaxRendered="true" will be updated.
onbeforedomupdate | The client-side script method to be called before DOM is updated
oncomplete | The client-side script method to be called after the request is completed
onsubmit | DHTML: The client-side script method to be called before an ajax request is submitted
process | Id['s] (in format of call UIComponent.findComponent()) of components, processed at the phases 2-5 in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
rendered | JSF: If "false", this component is not rendered
reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
similarityGroupingId | If there are any component requests with identical IDs then these requests will be grouped.
status | ID (in format of call UIComponent.findComponent()) of Request status component
timeout | Timeout (in ms) for request

Table 6.17. Component identification parameters

Name | Value
--- | ---
component-type | org.ajax4jsf.Poll
component-family | org.ajax4jsf.components.AjaxPoll
component-class | org.ajax4jsf.component.html.AjaxPoll
renderer-type | org.ajax4jsf.components.AjaxPollRenderer

#### 6.1.9.2. Creating the component with a Page Tag

To create the simplest variant on a page use the following syntax:

    <a4j:poll interval="500" reRender="grid"/>

#### 6.1.9.3. Creating the Component Dynamically Using Java

Example:

    import org.ajax4jsf.component.html.AjaxPoll;

    ...

    AjaxPoll myPoll = new AjaxPoll();

    ...

#### 6.1.9.4. Details of usage

The <a4j:poll> componet is used for periodical polling of server data. In order to use the component it's necessary to set an update interval. The "interval" attribute defines an interval in milliseconds between the previous response and the next request. The total period beetween two requests generated by the <a4j:poll> component is a sum of an "interval" attribute value and server response time. Default value for "interval" attribute is set to "1000" milliseconds (1 second). See an example of definition in the "Creating the component with a Page Tag" section.

The "timeout" attribute defines response waiting time in milliseconds. If a response isn't received during this period a connection is aborted and the next request is sent. Default value for "timeout" attribute isn't set.

The "enabled" attribute defines should the <a4j:poll> send request or not. It's necessary to render the <a4j:poll> to apply the current value of "enabled" attribute. You can use an EL-expression for "enabled" attribute to point to a bean property. An example of usage of mentioned above attributes is placed below:

Example:

    ...

    <a4j:region>

          <h:form>

                <a4j:poll id="poll" interval="1000" enabled="#{userBean.pollEnabled}" reRender="poll,grid"/>

          </h:form>

    </a4j:region>

    <h:form>

          <h:panelGrid columns="2" width="80%" id="grid">

               <h:panelGrid columns="1">

                    <h:outputText value="Polling Inactive" rendered="#{not userBean.pollEnabled}" />

                    <h:outputText value="Polling Active" rendered="#{userBean.pollEnabled}" />

                    <a4j:commandButton style="width:120px" id="control" value="#{userBean.pollEnabled?'Stop':'Start'} Polling" reRender="poll, grid">

                         <a4j:actionparam name="polling" value="#{!userBean.pollEnabled}" assignTo="#{userBean.pollEnabled}"/>

                    </a4j:commandButton>

              </h:panelGrid>

              <h:outputText id="serverDate" style="font-size:16px" value="Server Date: #{userBean.date}"/>

        </h:panelGrid>

    </h:form>

    ...

The example shows how date and time are updated on a page in compliance with data taken from a server. The <a4j:poll> componet sends requests to the server every second. "reRender" attribute of the <a4j:poll> contains poll's own `Id`. Hence, it is self rendered for applying the current value of "enabled" attribute.

## Notes:

- The form around the <a4j:poll> component is required.

- To make the <a4j:poll> component send requests periodically when it `limitToList` is set to "true", pass the <a4j:poll> ID to it `reRender` attribute.

Information about the "process" attribute usage you can find "Decide what to process" guide section.

#### 6.1.9.5. Relevant resources links

Visit the Poll page at RichFaces LiveDemo for examples of the component usage and their sources.

Useful examples and articles:

- "Create a Banner Using Effects and Poll" article at RichFaces Wiki gives an example of how to create an image banner using <rich:effect> and <a4j:poll> components;

- "Create an HTML Banner Using Effects and Poll" article at RichFaces Wiki brings the code of the way of creating an HTML banner banner using <rich:effect> and <a4j:poll> components;

- "RichFaces and Slideshow" thread in the RichFaces users forum contains an information and code on making a Slide Show with the help of the <a4j:poll> component;

Manage the RichFaces Users Forum for fresh issues about the component usage.

- Prev6.1.8. < a4j:jsFunction > ...
- Top of page
- Front page
- Next6.1.10. < a4j:push > ...