首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Progressbar与remoteCommand

Progressbar与remoteCommand
EN

Stack Overflow用户
提问于 2014-12-05 09:49:00
回答 1查看 548关注 0票数 0

我有以下远程命令:

代码语言:javascript
复制
<p:remoteCommand id="usedCall"
                 name="queryUsed"
                 oncomplete="fetchUsedMemory(#{performanceProvider.queryUsedMemory()})"
                 process="@all" />

它调用bean函数并将结果传递给脚本块中定义的fetchUsedMemory JS函数。我希望每2秒执行一次这个remoteCommand,直到取消为止,并将结果显示在ProgressBar上。我尝试了以下几点:

代码语言:javascript
复制
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以验证结果。然后是启动整个过程的函数:

代码语言:javascript
复制
function start() {
    PF('startButton1').disable();
    PF('cancelButton1').enable();
    window['progress'] = setInterval(queryUsed, 1000);
}

我试图在这里传递remoteCommand的名称,但它只被称为一次。没有人再对豆子打电话了。最后,这里是我的HTML:

代码语言:javascript
复制
    <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?谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-05 10:08:20

你可以使用<p:poll>,这里有个主意

xhtml

代码语言:javascript
复制
<p:poll interval="2" listener="#{performanceProvider.queryUsedMemory()}" 
        oncomplete ="updateMemory(xhr, status, args)" widgetVar="pollWV"
        process="@this" />

ManagedBean

代码语言:javascript
复制
public void queryUsedMemory() {
    RequestContext.getCurrentInstance().addCallbackParam("memory", getUsedMemory() + 10);
}

javascript

代码语言: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();
      }
   }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27313033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档