为了刷新数据,我使用质数poll
:
<p:poll id="myPoll" interval="#{controller.interval}"/>
并希望使用微调器控制更新间隔。
<p:spinner value="#{controller.interval}">
<p:ajax process="@this" update="myPoll"/>
</p:spinner>
Bean 属性的值按预期更新,但轮询间隔未更新。轮询由生成的脚本执行,其中包括间隔值。如何强制poll
重新生成更新脚本以包含新值,而无需提交/重新呈现整个表单?
如果你给它一个widgetVar
那么你可以用javascript操作它。
widget_form_j_idt19.stop();
widget_form_j_idt19.timer = 1;
widget_form_j_idt19.cfg.frequency = 1;
widget_form_j_idt19.start();
只需将其放入脚本中,您应该能够在 ajax 更新后将其更新为您想要的任何内容。
在这里解决:
我面临着类似的行为,只需在 bean 中设置值并将民意调查嵌入一个面板即可解决,该面板可以在每次民意调查后更新。否则,轮询只是 js 代码,而不是添加到 DOM 中。 否则,您可能会尝试在回调参数上执行 js 并刷新客户端的值。
<p:outputPanel id="infoPanel" >
<h:panelGrid columns="1">
<h1>TESTING POLLING</h1>
<h:outputText id="ts" value="TS Update:#{testPollBean.timeStamp}"/>
<h:outputText id="callNum" value="Call Number:#{testPollBean.callNumber}°"/>
<h:outputText id="interval" value="Interval:#{testPollBean.interval} second"/>
<h:outputText id="Stop" value="Stop:"#{testPollBean.stopPolling}"/>
</h:panelGrid>
</p:outputPanel>
<h:panelGrid id="panelPolling">
<p:poll id="durrPolling" async="true" stop="#{testPollBean.stopPolling}"
interval="#{testPollBean.interval}"
process="@this" partialSubmit="true" listener="#{testPollBean.listener}"
update="panelPolling infoPanel" widgetVar="polling"
autoStart="true" rendered="true"/>
</h:panelGrid>
@ViewScoped
@Named(value = "testPollBean")
public class TestPollBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger LOG = Logger.getLogger(TestPollBean.class);
private Calendar calendar;
private Date timeStamp;
private Date nextCall;
private int callNumber;
private int interval;
private boolean stopPolling;
private boolean listenerBusy;
@PostConstruct
public void init() {
this.calendar = Calendar.getInstance();
this.timeStamp = calendar.getTime();
this.nextCall = null;
this.callNumber = 0;
this.interval = 1;
stopPolling = false;
listenerBusy = false;
}
public void listener() {
callNumber ++;
LOG.info("-> Poll "+ callNumber + "° on thread " + Thread.currentThread().getId());
if (!listenerBusy) {
listenerBusy = true; // skip any other concurrence call
if (callNumber >= 30) {
//stopPolling = true;
this.interval = 30;
}
if (callNumber < 20) {
this.timeStamp = calendar.getTime();
calendar.add(Calendar.SECOND, interval);
nextCall = calendar.getTime();
LOG.info("t > Attennding "+ callNumber + "° call on thread " + Thread.currentThread().getId() + ". Sleeping ..." );
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
LOG.info("tt E R R O R ! ! ! t > Attennding "+ callNumber + "° call on thread " + Thread.currentThread().getId() );
}
//Later on we will try to adapt dynamically the interval.
} else {
LOG.info("t > Attennding inmediately "+ callNumber + "° call on thread " + Thread.currentThread().getId() + "." );
}
LOG.info("<- Poll "+ callNumber + "° on thread " + Thread.currentThread().getId());
listenerBusy = false;
} else {
LOG.info("<- Listener on thread " + Thread.currentThread().getId() + " dismiss call " + callNumber + "° cause is already busy.");
}
}
+ Getters / Setters
恕我直言;不要玩弄已经完成并起作用的东西。