简体   繁体   中英

How to access ZK component by JAVA api using its id only?

I have to search zkcomponent from complete loaded page which might have many nested windows and many levels, but i only have id of component as complete page is getting generated dynamically at a time. I have to find component or search component with specific id let say FirstName.

I am using Path.getComponent("/FirstName"); but it is returning null. Is there any way to find component from page without any parent id in ZK framework ?

Not sure if there is a simple solution, but a not simple solution would be going through the tree recursively....

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

You would start this with... Component comp = find( someComponent.getRoot(), myId);

In other words, go through the tree and in every new id space, query for your id. If it isn't found, go deeper down the tree. Of course this would require that your id is unique over the whole tree and not just inside its idspace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM