Search code examples
jsf-2

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.


Solution

  • 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.