Bootstrap styled messages

This demo shows you how you can add Bootstrap styled messages.

The messages are added server side to the facesContext object using the following code:

var msg = "I'm an info message, click the X and I'm gone forever";

facesContext.addMessage(
  null,
  new javax.faces.application.FacesMessage(
  javax.faces.application.FacesMessage.SEVERITY_INFO,
  msg,
  msg)
);

 

The lifetime of these message is very short: they are gone after a request is processed. If you want them to live longer (e.g. after redirecting a user to another page, you can implement a PhaseListener to store them temporarily in the sessionScope. The technique to do so is described here.