Search code examples
javaajaxjsfprimefacespolling

Adaptive polling with JSF and PrimeFaces


In order to refresh data, I use a primefaces poll:

<p:poll id="myPoll" interval="#{controller.interval}"/>

and would like to control the update interval with a spinner.

<p:spinner  value="#{controller.interval}">
  <p:ajax process="@this" update="myPoll"/>
</p:spinner>

The value of the bean property is updated as expected, but the polling interval isn't. The polling is performed by a generated script, which includes the interval value. How do I force the poll to regenerate the update script to include the new value without submitting/rerenderng the whole form?


Solution

  • If you give it a widgetVar then you can manipulate it with javascript.

    widget_form_j_idt19.stop();
    widget_form_j_idt19.timer = 1;
    widget_form_j_idt19.cfg.frequency = 1;
    widget_form_j_idt19.start();
    

    Just put it in a script and you should be able to update it to whatever you want after an ajax update.