Tuesday, February 14, 2012

Reflect live back end data on webpage using <a4j:poll/> component
(Seam, JSF, Richfaces)

You can use <a4j:poll/> component to do following things.
1. Run a java method periodically. (Ex:- Run auto save method)
2. Rerender another component periodically to display recent data from database.
3. Periodically run a javascript.
4. To accomplish three of above at the same time.

<h:form>
  <a4j:poll interval="1000" reRender="txtAlertCount" action="#{myBean.queryFromDb()}"/>
</h:form>
<h:outputText value="#{myBean.rowCount()}" id="txtAlertCount" />

Main attributes:
interval - time duration in milliseconds
action - method to be invoked in given intervals
reRender - Id of the component to be re-rendered
oncomplete - Javascript function to run after action is completed.
onsubmit - Javascript function to run before form submission

No comments:

Post a Comment