Example code for path getComponent

From Documentation
Revision as of 04:23, 23 July 2010 by Char (talk | contribs) (Created page with '{{ZKDevelopersGuidePageHeader}} == Example of Path.getComponent == In the following code, when the <tt>button</tt> is clicked, its label will be changed. <source lang="xml" > …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Documentationxample code for path getComponent
xample code for path getComponent


Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


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"/>
</window>

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");
		btn.setLabel("changed");
	}
}

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.



Last Update : 2010/07/23

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