@ManagedBean
@ViewScoped
public class MainBean {
public void saveData() {
FacesMessage message = null;
if(Math.random()<0.5){//simulating success/failure of saving data
message=new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Error during saving data", "Data cannot be saved...");
}
else{
message=new FacesMessage(FacesMessage.SEVERITY_INFO,
"Data saved", "Data has been saved successfully...");
}
RequestContext.getCurrentInstance().showMessageInDialog(message);
}
}
On Clicking the save data button various times:
Example Project
Dependencies and Technologies Used:
primefaces 6.1 primefaces
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.
datafactory 0.8: Library to generate data for testing.