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
Is there any more to the listener than that? I’ve implemented the code from the RichFaces LiveDemo and it doesn’t update the outputText component (in the debugger I’ve confirmed that the bean property is being updated).
Have you implemented the code here and gotten it to work:
http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_push.html
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.