0
我的問題是,是否有任何方式可以檢查某個特定Primefaces組件是否已經存在消息,如果不存在,則只能爲該組件添加消息。如何檢查組件的p:消息是否已存在?
我的問題是,是否有任何方式可以檢查某個特定Primefaces組件是否已經存在消息,如果不存在,則只能爲該組件添加消息。如何檢查組件的p:消息是否已存在?
您可以通過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
}
這對我來說非常合適。謝謝! – Pranjali