Reputation: 4274
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 Method
public void sendBatch() {
for (int i = 0; i < batch.size(); i++) {
batchModel.setProgress(Math.round(100 * (float) i / (float) batch.size()));
// Do stuff here
}
}
MODEL
@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
I am using PF 6. I tried with and without "update" tag, and I played around with the ajax tag, but no dice.
Upvotes: 3
Views: 2953
Reputation: 20168
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).
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}%"/>
Upvotes: 4