Following example shows how to use PrimeFaces ProgressBar where the progress task is indeterminate i.e. it is not known when task will finish. Indeterminate progressBar shows a cyclic animation without specific steps and the amount of progress indicated.
Example
JSF page
src/main/webapp/index.xhtml
<h:body>
<h2>PrimeFaces - Indeterminate ProgressBar Example</h2>
<h3>Trade Order Form</h3>
<h:form id="trade-order-form">
<!--... todo: put some form fields here ...-->
<p:commandButton value="Place Trade Order"
widgetVar="placeOrderButton"
actionListener="#{tradeOrderView.placeOrder}"
onstart="PF('placeOrderButton').disable();PF('progressPanel').show();"
oncomplete="PF('placeOrderButton').enable();PF('progressPanel').close();"/>
<br/><br/>
<p:panel widgetVar="progressPanel"
visible="false"
style="border:none;"
closable="true"
toggleable="true">
<p:progressBar style="height:20px;width:400px;"
mode="indeterminate"/>
</p:panel>
</h:form>
</h:body>
Note that "mode" attribute of progressBar is introduced in PrimeFaces 6.2, so it won't work in the older versions.
@ManagedBean
@ViewScoped
public class TradeOrderView {
public void placeOrder(ActionEvent ae) {
//simulating order placement
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
"Trade Order Status", "Order has been successfully placed.");
//RequestContext.getCurrentInstance().showMessageInDialog(message);
//above method deprecated in 6.2, use following instead
PrimeFaces.current().dialog().showMessageDynamic(message);
}
}
As seen in the comments, most of the methods in RequestContext have been deprecated in PrimeFaces 6.2. These methods are replaced in the helper class org.primefaces.PrimeFaces.
Output
Example Project
Dependencies and Technologies Used:
primefaces 6.2:
PrimeFaces is one of the most popular UI libraries in Java EE Ecosystem and widely used by software companies, world renowned brands, banks, financial institutions, insurance companies, universities and more.
[Description from primefaces-6.2.pom]
jsf-api 2.2.14:
This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
jsf-impl 2.2.14:
This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.