0

我的问题是,有什么方法可以检查特定 Primefaces 组件是否已经存在消息,如果没有,则只为该组件添加消息。

4

1 回答 1

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
      }
于 2012-12-22T05:21:49.773 回答