### 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.6. < a4j:push >

### 6.6.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.

Table 6.12. a4j : push 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 | boolean attribute which provides possibility to limit JSF tree processing(decoding, conversion/validation, value applying) to the component which send the request only
binding | 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 pushing. Default value is "true".
eventProducer | MethodBinding pointing at method accepting an PushEventListener with return type void. User bean must register this listener and send EventObject to this listener on ready.
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 element to set focus after request completed on client side
id | 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 push 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
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 | 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.13. 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.6.2. Creating on a page

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

### 6.6.3. Creating the Component Dynamically Using Java

    import org.ajax4jsf.component.html.AjaxPush;

    ...

    AjaxPush myPush = new AjaxPush();

    ...

### 6.6.4. Key attributes and ways 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.

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

### 6.6.5. Relevant resources links

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

- Prev6.5. < a4j:portlet >
- Top of page
- Front page
- Next6.7. < a4j:repeat >