2012-12-21 22 views

回答

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 
     } 
+0

這對我來說非常合適。謝謝! – Pranjali