2016-03-07 44 views
0

我必須從完整的加載頁面搜索zkcomponent,這個頁面可能有許多嵌套的窗口和很多層次,但是我只有組件的id,因爲一次完成的頁面動態生成。我必須找到具有特定ID的組件或搜索組件讓我們說FirstName。如何通過JAVA api使用其ID來訪問ZK組件?

我正在使用Path.getComponent(「/ FirstName」);但它返回null。有什麼方法可以在頁面中找到沒有任何父母id的組件?

回答

0

不知道如果有一個簡單的解決方案,但沒有簡單的解決方案將通過樹遞歸去....

public Component find(Component component, String id) { 
    if (component instanceof IdSpace) { 
     Component found = component.query("#" + id); 
     if (found != null) return found; 
    } 

    for(Component child : component.getChildren()) { 
     Component found = find(child, id); 
     if (found != null) return found; 
    } 

    return null; 
} 

你會用...... Component comp = find(someComponent.getRoot(), myId);

在此開始換句話說,通過樹和每個新的ID空間,查詢您的ID。如果找不到,可以深入樹下。當然,這需要你的id在整棵樹上獨一無二,而不僅僅是在它的空間中。