我有以下远程命令:
<p:remoteCommand id="usedCall"
name="queryUsed"
oncomplete="fetchUsedMemory(#{performanceProvider.queryUsedMemory()})"
process="@all" />它调用bean函数并将结果传递给脚本块中定义的fetchUsedMemory JS函数。我希望每2秒执行一次这个remoteCommand,直到取消为止,并将结果显示在ProgressBar上。我尝试了以下几点:
function fetchUsedMemory(usedMemory) {
var maxValue = jQuery('#TotalMemory').val();
var pbClient = PF('pbClient');
var newValue = usedMemory;
var percentg = (newValue / maxValue) * 100;
pbClient.setValue(percentg);
jQuery('#progressText').val('Max: ' + maxValue + ' NEW: ' + newValue + ' %: ' + percentg);
}此函数将更新进度条和inputText以验证结果。然后是启动整个过程的函数:
function start() {
PF('startButton1').disable();
PF('cancelButton1').enable();
window['progress'] = setInterval(queryUsed, 1000);
}我试图在这里传递remoteCommand的名称,但它只被称为一次。没有人再对豆子打电话了。最后,这里是我的HTML:
<p:panel id="mProgressPanel">
<p:progressBar id="progressBar" widgetVar="pbClient" style="width: 500px;" />
<p:inputText id="progressText" style="display: block; width: 1000px;" />
<f:facet name="footer">
<p:commandButton id="StartProgress" disabled="true"
type="button" onclick="start()"
value="Start"
widgetVar="startButton1" />
<p:commandButton id="StopProgress" disabled="true"
type="button" onblur="cancel()"
value="Stop"
widgetVar="cancelButton1"/>
</f:facet>
</p:panel>是否有办法使其工作,以便setInterval正确地调用remoteCommand?谢谢你的帮助!
发布于 2014-12-05 10:08:20
你可以使用<p:poll>,这里有个主意
xhtml
<p:poll interval="2" listener="#{performanceProvider.queryUsedMemory()}"
oncomplete ="updateMemory(xhr, status, args)" widgetVar="pollWV"
process="@this" />ManagedBean
public void queryUsedMemory() {
RequestContext.getCurrentInstance().addCallbackParam("memory", getUsedMemory() + 10);
}javascript
function updateMemory(xhr, status, args) {
if(args.memory) {
//update what ever you want
//Stop polling if the memory is 100
if(args.memory === 100) {
PF('pollWV').stop();
}
}
}https://stackoverflow.com/questions/27313033
复制相似问题