我在代码中使用了一个进度条,如下所示:
<p:commandButton value="#{msg['start.reindex']}"
widgetVar="reIndex"
action="#{generalConfigBean.reBuildIndex}"
onclick="PF('pbAjax').start(); PF('reIndex').disable();"
style="margin-left:25px;"/>
<p:progressBar id="progressBarPanel"
widgetVar="pbAjax"
ajax="true"
value="#{generalConfigBean.progress}"
labelTemplate="{value}% #{msg['reindex.msg']}"
global="false"
styleClass="animated"
interval="10"
style=" width: 100px; margin-left: 40px;">
<p:ajax event="complete" oncomplete="PF('reIndex').enable(); PF('pbAjax').cancel();"/>
</p:progressBar>
和generalConfigBean是这样的:
public class GeneralConfigBean extends BaseBean {
private Integer progress;
public void reBuildIndex() {
if (API.reIndex()) {
showMessage("reindex.successful", FacesMessage.SEVERITY_INFO);
} else {
showMessage("reindex.failed", FacesMessage.SEVERITY_INFO);
}
}
public void setProgress(Integer reIndexPercentage) {
this.progress = reIndexPercentage;
}
public Integer getProgress() {
progress = API.reIndexPercentage();
System.out.println(progress);
return progress;
}
}
当我点击按钮时,进度条的值增加到100%并且它匹配reBuildIndex()
,当它达到100%时,按钮将被启用。但是进度条中的动画与值不匹配,即使reBuildIndex
完成,进度条动画仍然有效!
下面的图片显示了它: