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

## Creating on a page

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

## Dynamical creation of a component from Java code

    import org.ajax4jsf.component.html.AjaxPush;
    ...
    AjaxPush myPush = new AjaxPush();
    ...

## Key attributes and ways of usage

The <a4j:push> implements reverse Ajax technique. The component makes requests to minimal code (not to JSF tree) in order to check presence of messages in a queue. If a message exists, a complete request is performed. <a4j:push> registers EventListener in the bean, which receives messages about an event presence.

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, or permanent connection.

Note:

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

## Relevant resources links

Here you can see the example of <a4j:push> usage and sources for the given example.