title: Progress bar primefaces on backend processing
body: <p>I would appreciate it if someone can give me some hints about progress bar and ajax back-end processing.</p>
  
  <p>To clarify what I need following are details:</p>
  
  <p>I have a command button to do some processing at the back-end.
  I would like to show a progress bar that reach the 100% when the backing bean finishes processing back-end instructions.
  I looked over many threads but no luck. Most of them did not show a concrete sample how to do that.
  Below is a snippet of my code:</p>
  
  <pre><code>&lt;/h:panelGrid&gt;
  &lt;p:commandButton id="btn" value="DoSomeAction"
  styleClass="ui-priority-primary" update="panel"
  onclick="PF('pbAjax').start();PF('startButton1').disable();"
  widgetVar="startButton1"
  actionListener="#{actionBean.DoSomeAction}" /&gt;
  
  &lt;p:progressBar widgetVar="pbAjax" ajax="true"
  value="#{progressBean.progress}" labelTemplate="{value}%"
  styleClass="animated"&gt;
  &lt;p:ajax event="complete" listener="#{progressBean.onComplete}"
  update="growl" oncomplete="startButton2.enable()" /&gt;
  &lt;/p:progressBar&gt;
  &lt;/p:panel&gt;
  </code></pre>
  
  <p>This is the code for the Progress Brean:</p>
  
  <pre><code>@ManagedBean(name="progressBean")
  public class ProgressBean implements Serializable {  
  
    private Integer progress;  
  
    public Integer getProgress() {  
      if(progress == null)  
        progress = 0;  
      else {  
        progress = progress + (int)(Math.random() * 35);      
        if(progress &gt; 100)  
        progress = 100;  
      }  
  
      return progress;  
    }  
  
    public void setProgress(Integer progress) {  
      this.progress = progress;  
    }  
  
    public void onComplete() {  
      FacesContext.getCurrentInstance().addMessage(null, new  FacesMessage(FacesMessage.SEVERITY_INFO, "Progress Completed", "Progress Completed"));  
    }  
  
    public void cancel() {  
      progress = null;  
    }  
  }  
  </code></pre>
  
  <p>The result of this code is just an empty progress bar and nothing happen when I click on my button.
  Thanks in advance. </p>