开发者

ZK how to get all components on page?

I am trying get all components on page and set them constraints. All components have i开发者_运维知识库d .I try to use IdSpace to get all ids on page but how to get Idspace ? I used

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

How to get IdSpace ?


Where did you write the code ?

My suggestion is to apply a composer to the root component , and iterate all the components inside.

Here's a runnable sample for iterating all the component and setvalue for all the labels. http://zkfiddle.org/sample/36t45ag/1-Iterate-all-the-components

And the code is here.

<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);
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜