O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – displaying FacesMessage using <p:messages>

Let us see how to display multiple FacesMessage using <p:messages>:

  1. 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>
  2. Add FacesMessage in the actionListener method as follows:
    public void addMultipleMsgs() { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample Info Msg", null)); FacesContext.getCurrentInstance().addMessage(null, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required