This example shows how to use Primefaces blockUI component to block user interface during some processing.
blockUI
<h:body> <h2>PrimeFaces - BlockUI Example</h2> <h:form id="registrationForm"> <p:inputText id="nameId" value="#{handlerBean.name}" required="true" label="Name"/> <p:commandButton id="saveBtn" value="Save" actionListener="#{handlerBean.save}" update="result"/> <br /> <p:blockUI block="registrationForm" trigger="saveBtn" > <p:graphicImage name="/progress.gif"/> </p:blockUI> <br /> <h:outputText id="result" value="#{handlerBean.name}" /> </h:form> </h:body>
Note that p:commandButton's 'actionListener' and 'update' params, and nested tag graphicImage of blockUI are optional for blockUI to work.
@ManagedBean @ViewScoped public class HandlerBean { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public void save() { System.out.println("saving name: " + name); try { //simulating some delay during processing TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); } } }
To try examples, run embedded tomcat (configured in pom.xml of example project below):
mvn tomcat7:run-war
Dependencies and Technologies Used: