Jsf rich:progressBar currentValue不适用于For循环?

Jsf rich:progressBar currentValue不适用于For循环?,jsf,richfaces,progress-bar,Jsf,Richfaces,Progress Bar,在RichFaces 4.1中,ManagedBean中的rich:progressBar“currentValue”不会使用for循环进行更新 progressBar.xhtml <h:form id="formProgress"> <h:commandLink action="#{progressBarBean.startProcess}" value="click here"/> <rich:progressBar mode

在RichFaces 4.1中,ManagedBean中的rich:progressBar“currentValue”不会使用for循环进行更新

progressBar.xhtml

 <h:form id="formProgress">
        <h:commandLink action="#{progressBarBean.startProcess}" value="click here"/>

        <rich:progressBar mode="ajax" value="#{progressBarBean.currentValue}" interval="1000" id="pb"
            enabled="#{progressBarBean.enabled}" minValue="0" maxValue="100">

            <h:outputText value="Retrieving #{progressBarBean.currentValue} of #{progressBarBean.totalRecords}" />
        </rich:progressBar>

    </h:form>

豆子

包ap;
导入java.io.Serializable;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.ViewScoped;
@ManagedBean
@视域
公共类ProgressBarBean实现了可序列化{
私有静态最终长serialVersionUID=8775622106408411357L;
启用私有布尔值=false;
私有整数记录;
私有整数值;;
公共字符串startProcess(){
setEnabled(真);
setTotalRecords(100);
返回null;
}
公共整数getCurrentValue(){
如果(isEnabled()){
对于(currentValue=0;currentValue
当我单击“单击此处”链接时,currentValue更新非常快,并突然达到totalRecords 100。它没有以增量方式更新(for循环中的当前值)。该方法返回的当前值不会更新进度条


请提供任何帮助。

有两个问题:您的Java代码没有执行您希望它执行的操作,并且您没有告诉页面进行更新(这不会自动发生)

再次查看
getCurrentValue()
:它将
currentValue
从0增加到100,并返回100的结果
#{progressBarBean.currentValue}
不关心(或知道)变量发生了什么,它只关心
getCurrentValue()
方法的结果

因此,为了让这一切正常运行,它必须如下所示:


询问是否有不清楚的地方。

如果我们使用“如果”条件并增加currentValue++,则上述解决方案有效。但当我们使用“for循环”时,它不起作用。对于(currentValue=0;currentValuepackage ap; import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; @ManagedBean @ViewScoped public class ProgressBarBean implements Serializable { private static final long serialVersionUID = 8775622106408411357L; private boolean enabled = false; private Integer totalRecords; private Integer currentValue;; public String startProcess() { setEnabled(true); setTotalRecords(100); return null; } public Integer getCurrentValue() { if (isEnabled()) { for(currentValue=0;currentValue < totalRecords;) { currentValue++; } } return currentValue; } public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public Integer getTotalRecords() { return totalRecords; } public void setTotalRecords(Integer totalRecords) { this.totalRecords = totalRecords; } }
<a4j:commandLink action="#{progressBarBean.startProcess}" value="click here" render="pb" execute="@this"/>
    <rich:progressBar mode="ajax" value="#{progressBarBean.currentValue}" interval="1000" id="pb"
        enabled="#{progressBarBean.enabled}" minValue="0" maxValue="100">
        <a4j:ajax event="begin" listener="#{progressBarBean.increment}" render="text"/>

        <h:outputText value="Retrieving #{progressBarBean.currentValue} of #{progressBarBean.totalRecords}" id="text" />
    </rich:progressBar>
public Integer getCurrentValue() {
    return currentValue;
}

public void increment() {
    if (isEnabled() && currentValue < totalRecords) {
        currentValue++;
    }
}