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:messag开发者_如何学Goes as well.
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.
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.
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
精彩评论