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