Implementing Ajax push with RichFaces

The following snippets illustrates how to implement an ajax push in a JSF application where RichFaces is set up. I am using this with a JSF application with Tomahawk extensions and RichFaces just for Ajax and Menus

Add the following in the XHTML:

<!-- Register an ajax listener on the bean -->
<a4j:push interval="1000" eventProducer="#{bean.addPushListener}"
    reRender="ajaxPanel" enabled="#{bean.pushing}" id="pushLstnr" />
<!-- the panel to be updated -->
<a4j:outputPanel id="ajaxPanel" ajaxRendered="true">
<h:messages layout="table" errorStyle="color:red"
      fatalStyle="color:red" infoStyle="color:blue" showDetail="true"
      showSummary="true" styleClass="loginError" />
</a4j:outputPanel>

Add the following to the Bean:

/**
  * Registers the ajax listener
  *
  * @param listener
  */
public void addPlanStatePushListener(EventListener listener) {
  synchronized (listener) {
    if (this.ajaxPushListener != listener) {
      this.ajaxPushListener = (PushEventListener) listener;
    }
  }
}

Now all you have to do is execute this call in your code where you need to update your browser:

// send event to browser:
ajaxPushListener.onEvent(new EventObject(this));

Have fun
Robert

2 Comments

  1. Hey John. I’ve been wanting to get back to you for quite some time. Sadly I don’t have any RichFaces application running anymore. I have moved on to JSF2.0 and PrimeFaces for my web applications. I am not anymore sure how I implemented the Ajax Push in RichFaces.

Comments are closed.