2011-07-20 26 views
0

我想在頁面上獲取所有組件並設置它們的約束。所有組件都有id。我嘗試使用IdSpace獲取頁面上的所有id,但是如何獲取Idspace?我用ZK如何獲取頁面上的所有組件?

Window main ; 
Page page ; 
page = main.getPage(); // This is null 

如何獲得IdSpace?

回答

2

你在哪裏編寫代碼?

我的建議是將一個作曲家應用到根組件 並迭代裏面的所有組件。

下面是一個可運行示例,用於迭代所有標籤的所有組件和setvalue。 http://zkfiddle.org/sample/36t45ag/1-Iterate-all-the-components

而代碼在這裏。

<window border="normal" title="hello" apply="pkg$.TestComposer"> 
    <label ></label> 
    <vlayout> 
      <label ></label> 
      <label ></label> 
      <label ></label> 
      <div> 
       <label ></label> 
       <label ></label>          
      </div>        
    </vlayout> 
</window> 

public void doAfterCompose(Component comp) throws Exception { 
    super.doAfterCompose(comp); 
    iterate(comp); 
} 

public void iterate(Component comp){ 

    /* 
    * do something for the component 
    */ 

    if(comp instanceof Label){ 
     ((Label)comp).setValue("Found label!"); 
    } 


    List<Component> list = comp.getChildren(); 
    for(Component child:list){ 
     iterate(child); 
    } 

} 
相關問題