Akshay
Akshay

Reputation: 1706

multiple <p:messages> on a JSF single page

This image should explain the problem clearly. I'm using p:messages from primefaces, but I guess it should apply to h:messages as well.

alt text

I want to associate a <p:messages> component with the form in which it is placed. In this case, the message is received by both the components.

The error is generated by the server, and I'm using this function:

public static void showErrorMessage(String errorString) {
    FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorString, "");
    FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}

How can I solve this? Thanks!

Edit: Clarification: Both the components are on the same page.

Upvotes: 0

Views: 5639

Answers (2)

kates
kates

Reputation: 11

An example in JSF + PrimeFaces 5.2

xhtml

<p:messages for ="Message1" showDetail="true" autoUpdate="true" closable="true" />
<p:messages for ="Message2" showDetail="true" autoUpdate="true" closable="true" />

Bean

FacesContext.getCurrentInstance().addMessage("Message1", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Hello 1"));

FacesContext.getCurrentInstance().addMessage("Message2", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Hello 2"));

This source give this answer and helped me

Upvotes: 1

Cagatay Civici
Cagatay Civici

Reputation: 6504

Is this a non-ajax request? p:messages of PrimeFaces 2.1 has redisplay(true by default) option, that might help. When redisplay is false, messages that are already displayed are ignored. Also you can use p:growl as an alternative.

Upvotes: 3

Related Questions