Time for action – displaying FacesMessage using <p:messages>
Let us see how to display multiple FacesMessage
using <p:messages>
:
Create a form with two
commandButton elements
and the<p:messages/>
component using the following code:<h:form style="width: 500px; padding-left: 10px;"> <p:panel header="Messages with All Severity levels"> <p:messages globalOnly="true" autoUpdate="true"/> <p:commandButton value="Show FacesMessages" actionListener="#{messagesController.addMultipleMsgs}"/> </p:panel> </h:form>
Add
FacesMessage
in theactionListener
method as follows:public void addMultipleMsgs() { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample Info Msg", null)); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,"Sample Warn Msg", null)); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR...