### 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.10. < a4j:push > available since 3.0.0

expand all

#### 6.1.10.1. Description

The <a4j:push> periodically perform Ajax request to server, to simulate 'push' data.

The main difference between <a4j:push> and <a4j:poll> components is that <a4j:push> makes request to minimal code only (not to JSF tree) in order to check the presence of messages in the queue. If the message exists the complete request is performed. The component doesn't poll registered beans but registers `EventListener` which receives messages about events.

#### 6.1.10.2. Details of Usage

The <a4j:push> implements reverse Ajax technique.

The bean, for example, could be subscribed to Java Messaging Service (JMS) topic or it could be implemented as Message Driven Bean (MDB) in order to send a message to the <a4j:push> component about an event presence. In the presence of the event some action occurs.

Thus, a work paradigm with the <a4j:push> component corresponds to an anisochronous model, but not to pools as for <a4j:poll> component. See the simplest example below:

Example:

    ...

    class MyPushEventListener implements PushEventListener {

        public void onEvent(EventObject evt) {

            System.out.println(evt.getSource());

                //Some action

        }

    }

    ...

Code for `EventListener` registration in the bean is placed below:

Example:

    ...

    public void addListener(EventListener listener) {

            synchronized (listener) {

                    if (this.listener != listener) {

                        this.listener = (PushEventListener) listener;

                   }

            }

    }

    ...

A page code for this example is placed below.

Example:

    ...

    <a4j:status startText="in progress" stopText="done"/>

    <a4j:form>

         <a4j:region>

               <a4j:push reRender="msg" eventProducer="#{pushBean.addListener}" interval="2000"/>

         </a4j:region>

         <a4j:outputPanel id="msg">

              <h:outputText value="#{pushBean.date}">

                   <f:convertDateTime type="time"/>

              </h:outputText>

         </a4j:outputPanel>

         <a4j:commandButton value="Push!!" action="#{pushBean.push}" ajaxSingle="true"/>

    </a4j:form>

    ...

The example shows how date is updated on a page in compliance with data taken from a server. In the example "interval" attribute has value "2000". This attribute defines an interval in milliseconds between the previous response and the next request. Default value is set to "1000" milliseconds (1 second). It's possible to set value equal to "0". In this case connection is permanent.

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. Usage of "interval" and "timeout" attributes gives an opportunity to set short polls of queue state or long connections.

## Note:

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

#### 6.1.10.3. Reference Data

Table of <a4j:push> attributes.

Table 6.10. Component Identification Parameters

Name | Value
--- | ---
component-type | org.ajax4jsf.Push
component-family | org.ajax4jsf.components.AjaxPush
component-class | org.ajax4jsf.component.html.AjaxPush
renderer-type | org.ajax4jsf.components.AjaxPushRenderer

#### 6.1.10.4. Relevant Resources Links

On RichFaces LiveDemo page you can found some additional information for <a4j:push> component usage.

Refer to Simple IRC Widget with <a4j:push> article to find out real-world usage of the <a4j:push> component.

- Prev6.1.9. < a4j:poll > a...
- Top of page
- Front page
- Next6.1.11. < a4j:queue > ...