I'm pretty new to JSF so I need someone who can help me. I'm trying to implement a progress bar in a page, so I've followed this example; it's clear enough but my problem is that the value for the "value" attribute is not calculated in the bean (CLASS_A), but in an util class (CLASS_B) invoked from it. In this context, I've created a "accomplishedPercentage" variable in CLASS_A and updated it from CLASS_B so I can use it in a xhtml page but is not getting updated; I also tried creating a ProgressBarBean class (anotated with @ManagedBean and @SessionScoped) and invoke the method to calculate the progress from CLASS_B but I don't know why I'm always getting the ProgressBarBean as null (I'm injecting it with @ManagedProperty). Could someone help me? some example or point me what I'm doing wrong? Thanks in advance.
Some pieces of code:
This is the progress bar in the view:
<rich:progressBar value="#{progressBar.accomplishedPercentage}"
interval="2000" label="#{progressBar.accomplishedPercentage} %"
enabled="#{oaBean.showProgressBar}" minValue="-1" maxValue="100"
reRenderAfterComplete="createFormPanel">
</rich:progressBar>
ProgressBarBean
@ManagedBean(name="progressBar")
@SessionScoped
public class ProgressBarBean implements Serializable {
private static final long serialVersionUID = 1L;
private Long accomplishedPercentage;
@PostConstruct
public void init() {
accomplishedPercentage = 0L;
}
public void incrementAccomplishedPercentage (Long inc) {
this.setAccomplishedPercentage(this.getAccomplishedPercentage() + inc);
}
//getter and setter for accomplishedPercentage
}
The progress bar is then injected in CLASS_B through @ManagedProperty(value="#{progressBar}")
private ProgressBarBean progressBar;
and invoke the method incrementAccomplishedPercentage
, but as I said, I'm getting the progressBar
with a null value.
EDIT 1
Now I'm receiving an instance of ProgressBarBean, but the problem is that never gets updated the value of the progress bar in the UI: the method getAccomplishedPercentage
is only invoked when loading the page (so it is always 0), not during the processing every 2 seconds.
I suppose that the progress bar itself is no related to the button which should start it. Here is full definition of the progress bar:
<p:dialog modal="true" widgetVar="statusDialog" header="Status"
draggable="false" closable="false" resizable="false">
<rich:progressBar value="#{oaBean.accomplishedPercentage}"
interval="1000" label="#{oaBean.accomplishedPercentage} %"
enabled="#{oaBean.showProgressBar}" minValue="-1" maxValue="100"
reRenderAfterComplete="createFormPanel">
</rich:progressBar>
</p:dialog>
And this is the definition of the command button:
<p:commandButton id="generate" value="Generate"
oncomplete="generateDialogDocumento.hide() onclick="PrimeFaces.monitorDownload(start, stop)"
icon="ui-icon-arrowthichk-s" ajax="false">
<p:fileDownload value="#{oaBean.file}" />
</p:commandButton>
I've tried to link both controls but I couldn't, does anybody know what should I do?
Regards
EDIT 2
Based on @Andy's suggestion I changed the progress bar to primefaces, but in this case I don't see any progress being displayed (not even 0). This is now the code for the commandButton:
<p:commandButton id="generate" value="Generate"
oncomplete="generateDialogDocumento.hide()" onclick="PrimeFaces.monitorDownload(start, stop); statusDialog.show();"
icon="ui-icon-arrowthichk-s" ajax="false">
<p:dialog modal="false" widgetVar="statusDialog" header="Status"
draggable="false" closable="false" resizable="false">
<p:growl id="growl" />
<p:progressBar widgetVar="pbAjax" ajax="true" value="#{progressBar.accomplishedPercentage}" labelTemplate="#{progressBar.accomplishedPercentage}%" >
<p:ajax event="complete" listener="#{progressBar.onComplete}" update="growl" oncomplete="statusDialog.hide()"/>
</p:progressBar>
</p:dialog>
<p:fileDownload value="#{oaBean.file}" />