StaticMessage component can be used to display a message without the use of a FacesMessages.
<p:growl id="growl"/>
<div class="card">
<h5>Basic</h5>
<div class="grid">
<div class="col-12 md:col-4">
<p:staticMessage severity="info" summary="INFO" detail="Message Content" style="width: 100%"/>
</div>
<div class="col-12 md:col-4">
<p:staticMessage severity="warn" summary="WARN" detail="Message Content" style="width: 100%"/>
</div>
<div class="col-12 md:col-4">
<p:staticMessage severity="error" summary="ERROR" detail="Message Content" style="width: 100%"/>
</div>
</div>
<h5>Closable</h5>
<p:staticMessage severity="warn" summary="Warning" style="width: 100%"
detail="This is a static message that can be closed by the user."
closable="true" rendered="#{not messagesView.closed}">
<p:ajax event="close" listener="#{messagesView.onClose()}" update="growl"/>
</p:staticMessage>
</div>
@Named
@ViewScoped
public class MessagesView implements Serializable {
private boolean closed;
public void info() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "Message Content"));
}
public void warn() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Warning", "Message Content"));
}
public void error() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Message Content."));
}
public void onClose() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Message is closed", null));
closed = true;
}
public boolean isClosed() {
return closed;
}
}