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="ui-button-danger" />
</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>
@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;
}
}