Create new RichFaces Documentation Jira issue

This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

6.1.10.  < a4j:push > available since 3.0.0

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.19. a4j : push attributes

Attribute Name Description
actionMethodBinding 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
actionListenerMethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingleLimits 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
bypassUpdatesIf "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
dataSerialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
enabledEnables/disables pushing. Default value is "true".
eventProducerMethodBinding pointing at method accepting an PushEventListener with return type void. User bean must register this listener and send EventObject to this listener on ready.
eventsQueueName 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.)
focusID 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
ignoreDupResponsesAttribute 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
immediateTrue 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
intervalInterval (in ms) for call push requests. Default value is "1000"ms (1 second).
limitToListIf "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.
onbeforedomupdateThe client-side script method to be called before DOM is updated
oncompleteThe client-side script method to be called after the request is completed
processId['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
reRenderId['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
similarityGroupingIdIf there are any component requests with identical IDs then these requests will be grouped.
statusID (in format of call UIComponent.findComponent()) of Request status component
timeoutTimeout (in ms) for request

Table 6.20. Component identification parameters

NameValue
component-typeorg.ajax4jsf.Push
component-familyorg.ajax4jsf.components.AjaxPush
component-classorg.ajax4jsf.component.html.AjaxPush
renderer-typeorg.ajax4jsf.components.AjaxPushRenderer


<a4j:push reRender="msg" eventProducer="#{messageBean.addListener}" interval="3000"/>
import org.ajax4jsf.component.html.AjaxPush;

...
AjaxPush myPush = new AjaxPush();
...

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.

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