5 Replies Latest reply on Dec 31, 2008 3:22 PM by Dirk Ho

    How to use facesMessages.add or facesMessages.instance().add

    Dirk Ho Newbie


      I read in Seam Reference that it is possible to use facesMessages.add and/or facesMessages.instance().add to add messages to the next rendered page.

      Now, I have a page buyCar.xhtml. If the user bought a car and it was written to the database successfully, there is a rule in my buyCar.page.xml where I defined, that the user is redirected to a page successful.xhtml.

      This page looks like that:

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      <ui:define name="body">
          <h1>#{messages['website.headline.successful']}</h1><br />
              <h:messages />

      Now I thought, that h:messages is replaces by my message added to facesMessages.add oder facesMessages.instance().add, but nothing is shown expected the text between <h1></h1>.

      Can you help me and tell me, what I have to do to show this message?

      My Bean looks like that:

      public class BuyCarAction implements BuyCar {
                      Log log;
                      private EntityManager em;
                      private FacesMessages facesMessages;
                  public String buyIt() {
                              Bestellung bestellungNeu = bv.createBestellung(bestellung);
                              log.info("BestellungNeu: " + bestellungNeu);
                              final Kunde kundeNeu = bestellungNeu.getKunde();
                              log.info("Kunde Neue Bestellung " + kundeNeu);
                      FacesMessages.instance().add("Kauf war erfolgreich");
                      return "success";

      Thanks and best regards,