进度条设置间隔与远程命令
Progressbar setInterval with remoteCommand
我有以下远程命令:
<p:remoteCommand id="usedCall"
name="queryUsed"
oncomplete="fetchUsedMemory(#{performanceProvider.queryUsedMemory()})"
process="@all" />
它调用一个 bean 函数并将结果传递给脚本块中定义的 fetchUsedMemory JS 函数。我想每 2 秒执行一次此远程命令,直到取消并在进度条上显示结果。我尝试了以下方法:
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);
}
此函数将更新进度条和输入文本以验证结果。然后启动整个过程的函数:
function start() {
PF('startButton1').disable();
PF('cancelButton1').enable();
window['progress'] = setInterval(queryUsed, 1000);
}
我试图在这里传递远程命令的名称,但它只被调用一次。没有对豆子进行进一步的呼叫。最后这是我的 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 正确调用远程命令?感谢您的帮助!
你可以使用<p:poll>
,这里有一个想法
.xhtml
<p:poll interval="2" listener="#{performanceProvider.queryUsedMemory()}"
oncomplete ="updateMemory(xhr, status, args)" widgetVar="pollWV"
process="@this" />
管理豆
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();
}
}
}
相关文章:
- 当我点击jsf中的primefaces命令按钮时,如何获得点击事件
- 如何使用Socket.io将命令从客户端发送到服务器
- 通过命令行/批处理文件打开页面时,将javascript代码注入Google Chrome
- 命令行中的Uglify js;不要弄乱变量名
- http.listen()在运行时接受终端命令
- 如何在没有单词的情况下从命令行运行Node.js程序'节点'
- 如何将给定的curl命令复制为jquery ajax请求
- 打开抽屉的Javascript打印命令
- Web控制台命令不起作用
- 如何使用脚本在jsf中执行命令按钮的自动点击
- 类似HTML命令行的文本框
- 命令“;节点"做
- 节点JS express和控制台输出到命令行与浏览器
- 如何将.json文件作为参数导入.js文件并使用命令行启动它
- 编辑弹出窗口的HTML的单击命令
- 为什么我的关键命令不起作用
- Javascript不能在一个命令中使用函数参数
- 最小化CSS/JS文件,并使用命令行创建一个文件
- 在Flask中使用.getJSON请求时,只运行一次命令
- 如何在nodejs的单独线程上执行dos命令