Search code examples
javazk

How do I find the root component of a given component in zk?


In my viewmodel I have the following code:

@Command
public void onFinish(@BindingParam(value = "myButton") Button myButton) {
        Component root = myButton.getParent().getParent().getParent();
        ...
}

Is there a more elegant way to find the root component of any given component? The expression above has to be altered every time I change the zul.

P.S. I am new to zkoss..:)


Solution

  • Assuming your root component has an id, you could do the following:

    Component root = myButton.getPage().getFellow("id-of-root-component");