How to use facesMessages.add or facesMessages.instance().add
mean.meanmachine.gmx.at Dec 28, 2008 2:34 PMHello,
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" template="layout/template.xhtml"> <ui:define name="body"> <h1>#{messages['website.headline.successful']}</h1><br /> <h:messages /> </ui:define> </ui:composition>
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:
... @Stateful @Scope(CONVERSATION) @Name("buyCarAction") public class BuyCarAction implements BuyCar { @Logger Log log; ... @PersistenceContext private EntityManager em; @In 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,
Dirk