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>
package org.primefaces.showcase.view.message;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import java.io.Serializable;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@ViewScoped
@RegisterForReflection(serialization = true)
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 fatal() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Fatal", "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;
}
}