我的问题是,我们可以通过任何方式检查是否已经存在针对特定PrimeFaces组件的消息,如果不是,则仅在该组件中添加消息。
您可以通过FacesContext
对象访问特定组件的排队消息。以下代码应起作用:
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
}