a4j:poll

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

## Creating on a page

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

Example:

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

## Creating the Component Dynamically Using Java

Example:

    import org.ajax4jsf.component.html.AjaxPoll;
    ...
    AjaxPoll myPoll = new AjaxPoll();
    ...

## Key attributes and ways 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 on a page" 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 for <a4j:poll> contains value of its own Id. Hence, it renders itself for applying the current value of "enabled" attribute.

Note:

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

Note:

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.

## Relevant resources links

In RichFaces Wiki article "Creating a Banner Using Effects and Poll" you can get additional information how to create an image banner using <rich:effect> and <a4j:poll> components and also you can figure out how to create an HTML banner in RichFaces Wiki article "Creating an HTML Banner Using Effects and Poll" .

In RichFaces Cookbook article on Slide Show" you can find information how to make a Slide Show with help of the <rich:effect> and <a4j:poll> components.

On RichFaces Live Demo page you can see the example of <a4j:poll> usage and sources for the given example.

The additional information about component usage you can find in RichFaces Users Forum .