【问题标题】:How to check if p:message already exists for a component?如何检查组件的 p:message 是否已存在?
【发布时间】:2012-12-21 06:29:19
【问题描述】:

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

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    您可以通过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
          }
    

    【讨论】:

      猜你喜欢
      • 2019-11-25
      • 2021-11-28
      • 1970-01-01
      • 2020-10-19
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      • 2021-03-18
      • 2011-03-26
      相关资源
      最近更新 更多