2011-11-18 39 views
3

我有幾個不同的primefaces對話框,並且我實現了一個收聽器,收到org.primefaces.event.CloseEvent。在此關閉事件的內部,我可以訪問生成關閉事件org.primefaces.component.dialog.Dialog的UI組件。JSF 2.0 + Primefaces:查找某種類型的所有子組件

我的問題是我需要訪問對話框中的所有輸入字段。這些輸入字段可能會隱藏在對話框的其他組件中。有沒有人知道一個簡單的方法(一個方法調用)來檢索所有的輸入字段遞歸的子組件?

+0

我不覺得有什麼,它正是你正在尋找任何方便的方法。但是也可以在遍歷列表時使用'getChildren'方法和過濾器。 http://javaserverfaces.java.net/nonav/docs/2.1/javadocs/index.html –

回答

0

這裏是解決方案,我能拿出我自己:

private void doStuffToInputFields(UIComponent component) { 
    if (component instanceof UIInput) { 
     UIInput source = (UIInput) component; 

     //Add your custom logic here to do stuff with your input fields 

     return; 
    } 

    Iterator<UIComponent> children = component.getFacetsAndChildren(); 

    if (children != null) { 
     UIComponent child = null; 

     while (children.hasNext()) { 
      child = (UIComponent) children.next(); 
      resetInputFields(child); 
     } 
    } 
} 
相關問題