Reputation: 3257
I'm trying to display global error messages which are sent from EJB with:
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Please select a path first", "title"));
right now the JSF has the following code:
<h:messages globalOnly="true"/>
The above however doesn't work because the JSF page is not rerendered. Notice I am able to make the above work using primefaces, if I substitute the JSF code with the following:
<p:messages globalOnly="true" showDetail="true" autoUpdate="true" closable="true" />
However I don't want to use primefaces and I want a pure JSF solution. Notice also I don't want the h:messages to be inside a form as there's no button to click, I want the h:messages to be auto updated from the EJB but without using primefaces.
Upvotes: 0
Views: 6405
Reputation: 582
You have to render the <h:messages />
else it wont show.
You can achive this by rendering the message from the managedbean.
<h:messages id="globalMessage" />
And in your managedBean you place a code to render the messages after your
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Please select a path first", "title"));
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds()
.add("globalMessage");
But be sure you have the correct Id to be rendered.
Upvotes: 3