Reputation: 535
My question is that is there any way by which we can check if a message is already present for a specific Primefaces component,and if not then only add message for that component.
Upvotes: 0
Views: 1175
Reputation: 20691
You can access the queued messages for a specific component via the FacesContext
object. The following code should work:
FacesContext context = FacesContext.getCurrentInstance(); //obtain a reference to the FacesContext
String desiredClientId = "componentId"; //You should already have the client side id of the component you want to operate with
Iterator<FacesMessage> messageQueue = context.getMessages(desiredClientId); //Obtain an Iterator for a List of possible queued messages for the component id you've provided.
if(messageQueue.hasNext()){
//the component has messages queued, do whatever you want
}
else{
no messages, do whatever you want
}
Upvotes: 2