Difference between revisions of "Example code for path getComponent"

From Documentation
(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" > …')
 
m (correct highlight (via JWB))
 
Line 3: Line 3:
 
== Example of Path.getComponent ==
 
== Example of Path.getComponent ==
  
In the following code, when the <tt>button</tt> is clicked, its label will be changed.
+
In the following code, when the <code>button</code> is clicked, its label will be changed.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 28: Line 28:
  
 
== Another way, getFellow ==
 
== Another way, getFellow ==
<tt>getFellow</tt> is another api to get the component. But it is not recommended. For simplicity and consistency, use <tt>Path.getComponent</tt> instead.
+
<code>getFellow</code> is another api to get the component. But it is not recommended. For simplicity and consistency, use <code>Path.getComponent</code> instead.
  
 
== omit Path.getComponent ==
 
== omit Path.getComponent ==

Latest revision as of 02:57, 20 January 2022

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 : 2022/01/20

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