简体   繁体   English

使用progressBar Primefaces停止通话

[英]Stop call with progressBar Primefaces

Cancelling the progressBar call after sharing 100%? 共享100%后要取消progressBar调用吗? I've tried to do so: 我尝试这样做:

public void doJs() {
    RequestContext ctx = RequestContext.getCurrentInstance();
    context.execute("progress.cancel();");
}

Or call the PF('progress').cancel(); 或调用PF('progress').cancel(); , but without success. ,但没有成功。 Follow my progressBar . 跟随我的progressBar

<p:progressBar widgetVar="progress" ajax="true" global="false"
                    value="#{usarLayoutBean.porcentagem}" labelTemplate="{value}%"
                    styleClass="animated">
    <p:ajax event="complete" listener="#{usarLayoutBean.doJs()}"/>
</p:progressBar>

The code below works for the progress bar. 下面的代码适用于进度栏。 The progress bar stops at 100 and getProgress() is not called again. 进度条停在100,并且不会再次调用getProgress()。 The onComplete() is called once the Integer progress is equal to 100. 一旦Integer进度等于100,就会调用onComplete()。

<h:form>
        <p:growl id="growl" />
        <p:commandButton value="Start" type="button"
            onclick="PF('pbAjax').start();" />

        <p:progressBar widgetVar="pbAjax" ajax="true"
            value="#{progressBean.progress}" labelTemplate="{value}%"
            styleClass="animated" global="false">
            <p:ajax event="complete" listener="#{progressBean.onComplete}"
                update="growl" />
        </p:progressBar>
</h:form>

Managed Bean 托管豆

package com.test;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class ProgressBean {
    private Integer progress;

    public Integer getProgress() {
        System.out.println("getProgress() Old - " + progress);

        if (progress == null) {
            progress = 0;
        } else {
            progress = progress + (int) (Math.random() * 35);

            if (progress > 100) // Only when progress = 100 does the onComplete() method gets called.
                progress = 100;
        }

        System.out.println("getProgress() New- " + progress);
        return progress;
    }

    public void setProgress(Integer progress) {
        System.out.println("setProgress()" + progress);
        this.progress = progress;
    }

    public void onComplete() {
        System.out.println("onComplete()");

        //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Progress Completed"));
        progress = null;
    }

}

Output 输出量

getProgress() Old - null
getProgress() New- 0
getProgress() Old - 0
getProgress() New- 24
getProgress() Old - 24
getProgress() New- 50
getProgress() Old - 50
getProgress() New- 82
getProgress() Old - 82
getProgress() New- 100
onComplete()

JSF 2.2.4 , Primefaces 5.3 , Tomcat 8 JSF 2.2.4,Primefaces 5.3,Tomcat 8

  1. The code below won't stop progressBar 下面的代码不会停止progressBar

    context.execute("progress.cancel();"); context.execute(“ progress.cancel();”);

Because the correct way is 因为正确的方法是

 context.execute("PF('progress').cancel()");

on the doJs() method. 在doJs()方法上。

  1. Double check if getPorcentagem is returning 100 at least once. 仔细检查getPorcentagem是否至少返回100。 If this happens, the progress stops automatically. 如果发生这种情况,进度将自动停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM