Example code for path getComponent

From Documentation

Jump to: navigation, search

Example of Path.getComponent

In the following code, when the button is clicked, its label will be changed.

<window id="w" apply="MyComposer">
	<button id="b" label="ok" forward="onClick=onChangeLabel"/>

And MyComposer.java

import org.zkoss.zk.ui.Path;
import org.zkoss.zk.ui.util.GenericComposer;
import org.zkoss.zul.Button;

public class MyComposer extends GenericComposer {
	Button btn = new Button();
	public void onChangeLabel(){
		btn = (Button)Path.getComponent("/w/b");

Another way, getFellow

getFellow is another api to get the component. But it is not recommended. For simplicity and consistency, use Path.getComponent instead.

omit Path.getComponent

Please refer to section Auto-wire the Components and Beans of the small talk : ZK MVC Made Easy. ZK has provided autowire feature, you can save your time and write less code.

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.