Reputation: 1050
In my facelet, I am working with a progressbar. Now the progressbar's progress is coming from a Holder class which is in SessionScope and my backing bean is in RequestScope. Once the progress is 100% and my activity is finished, what I am doing is setting the progress to 0. Now next time again within the same page when I am clicking on the export button, progress is showing first to 100% and then going down to 0 and then showing actual progress.
My question is when I set the progress is 0 already then why second time initially it is displaying 100 as the value? Any help.
Code is:
<p:commandLink id="excelExport"
actionListener="#{studentDetailsBean.export}" ajax="false"
onclick="progressDisplay.show();">
<p:graphicImage library="img" name="excel.png" width="20" />
</p:commandLink>
<p:tooltip for="excelExport" value="Export to Excel"
showEffect="fade" hideEffect="fade" />
<p:dialog id="progress_dialog" dynamic="true"
onShow="pbAjax.start();pbAjax.setValue(0);" width="300" position="center"
widgetVar="progressDisplay" resizable="false" draggable="false"
modal="true" showHeader="false">
<p:progressBar id="progressBar" widgetVar="pbAjax" ajax="true"
value="#{studentDetailsBean.progressBarHolder.progress}"
labelTemplate="Exporting..." style="margin-bottom:0;"
interval="2000">
<p:ajax event="complete"
listener="#{studentDetailsBean.onProgressComplete}"
oncomplete="pbAjax.cancel();progressDisplay.hide()" />
</p:progressBar>
</p:dialog>
Upvotes: 1
Views: 1912
Reputation: 4423
Once rendered, the progress bar relies on a javascript object that checks the model repeatedly for modifications.
When it reaches the 100%, the javascript object stops checking the managedbean and preserves it's former state.
When you start another process, the components remains on 100% until it does the first progress checking.
To guarantee that the javascript object (accessible through widgetVar) will start on 0, you will need to do as fallows (from Primefaces Demo):
XHTML
<p:progressBar widgetVar="pbAjax" ajax="true" value="#{progressBean.progress}" labelTemplate="{value}%" styleClass="animated">
<p:ajax event="complete" listener="#{progressBean.onComplete}" update="growl" oncomplete="startButton2.enable()"/>
</p:progressBar>
<p:commandButton value="Start" type="button" onclick="pbAjax.setValue(0); PF('pbAjax').start(); PF('startButton2').disable();" widgetVar="startButton2" />
NOTE: pbAjax.setValue(0);
Upvotes: 3