我的问题是,我们可以通过哪种方式检查特定Primefaces组件是否已存在消息,如果没有,则只为该组件添加消息。
答案 0 :(得分:2)
您可以通过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
}