Primefaces进度栏未更新? [英] Primefaces progressbar not updating?

查看:47
本文介绍了Primefaces进度栏未更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的进度栏没有更新,为什么?控制器方法将按其应有的方式调用,并且progess变量将正确递增:

My progressbar is not updated, why ? The controller method is called as it should and the progess variable is correctly incremented:

XHTML

<p:dialog>
    <h:outputLabel value="Count:" for="batchCount"/>
    <p:inputText id="batchCount" required="true"
        value="#{batchModel.count}">
    </p:inputText>

    <p:commandButton id="generateBatchButton" value="GO"
        actionListener="#{batchController.sendBatch()}"
        onclick="PF('progressVar').start();"
        oncomplete="PF('dialogBatchParams').hide();"/>

    <p:progressBar id="progressBar"
        widgetVar="progressVar" 
        value="#{batchModel.progress}" 
        labelTemplate="{value}%">
    </p:progressBar>
</p:dialog>

CONTROLLER方法

public void sendBatch() {       
    for (int i = 0; i < batch.size(); i++) {
        batchModel.setProgress(Math.round(100 * (float) i / (float) batch.size()));
        // Do stuff here
    }
}

模型

@Named
@ViewScoped // or @SessionScoped 
public class BatchModel implements Serializable {
    private static final long serialVersionUID = 1L;

    private int count = 100;
    private int progress;

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getProgress() {
        return progress;
    }

    public void setProgress(int progress) {
        this.progress = progress;
    }
}

我的进度已正确更新,登录时会显示以下输出:

My progress is correctly updated, I get this output when logging it:

2016-10-19 10:08:49,707 INFO controller.BatchController -> Sending batch
0
10
20
30
40
50
60
70
80
90
2016-10-19 10:08:57,432 INFO controller.BatchController -> Done sending batch

我正在使用PF6.我尝试使用和不使用"update"标签,并且使用了ajax标签,但没有骰子.

I am using PF 6. I tried with and without "update" tag, and I played around with the ajax tag, but no dice.

推荐答案

您的问题始于 RequestScoped bean.这些将在每个请求中创建.由于更新酒吧需要一个请求,因此您将获得一个进度设置为 0 的新bean.
最好在您的bean(和控制器)上使用 ViewScoped .

Your question started of with a RequestScoped bean. Those are created each request. Since an update of the bar requires a request, you will get a new bean with progress set to 0 again.
It's best to use ViewScoped on your bean (and controller).

此外,您在进度栏中缺少 ajax ="true" (它希望您在客户端进行更新).您应该将其更改为:

Also, you are missing ajax="true" in your progress bar (it expects you to do the updates on the client side). You should change it to:

<p:progressBar id="progressBar"
               ajax="true"
               widgetVar="progressVar" 
               value="#{batchModel.progress}" 
               labelTemplate="{value}%"/>

这篇关于Primefaces进度栏未更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆