Messages components are used to display FacesMessages.
<div class="card">
<p:tooltip/>
<h:form>
<p:messages id="messages" showDetail="true" closable="true">
<p:autoUpdate/>
</p:messages>
<h5 class="mt-0">Severities</h5>
<p:commandButton value="Info" action="#{messagesView.info}" styleClass="mr-2"/>
<p:commandButton value="Warn" action="#{messagesView.warn}" styleClass="mr-2 ui-button-warning"/>
<p:commandButton value="Error" action="#{messagesView.error}" styleClass="mr-2 ui-button-danger"/>
<p:commandButton value="Fatal" action="#{messagesView.fatal}" styleClass="mr-2 ui-button-help"/>
</h:form>
</div>
<div class="card">
<h:form>
<h5>Validation</h5>
<h:panelGrid id="grid" columns="3" cellpadding="7">
<p:outputLabel for="default" value="Default:"/>
<p:inputText id="default" required="true"/>
<p:message for="default"/>
<p:outputLabel for="txt" value="Text:"/>
<p:inputText id="txt" required="true"/>
<p:message for="txt" display="text"/>
<p:outputLabel for="icon" value="Icon:"/>
<p:inputText id="icon" required="true"/>
<p:message for="icon" display="icon"/>
<p:outputLabel for="tt" value="Tooltip:"/>
<p:inputText id="tt" required="true"/>
<p:message for="tt" display="tooltip"/>
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" update="grid" styleClass="mt-3"/>
</h:form>
</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;
}
}