Composite Component"
Line 4: | Line 4: | ||
Like a [[ZK Developer's Reference/UI Composing/Macro Component|macro component]], a composite component is an approach to compose a component based on a template. Unlike a macro component, a composite component has to create and wire the child components by itself, and handle ID space if necessary. The advantage is that a composite component can extend from any component, such as <javadoc>org.zkoss.zul.Row</javadoc>, such that it is easier to fit to any situation (and no need of the inline concept). | Like a [[ZK Developer's Reference/UI Composing/Macro Component|macro component]], a composite component is an approach to compose a component based on a template. Unlike a macro component, a composite component has to create and wire the child components by itself, and handle ID space if necessary. The advantage is that a composite component can extend from any component, such as <javadoc>org.zkoss.zul.Row</javadoc>, such that it is easier to fit to any situation (and no need of the inline concept). | ||
+ | |||
+ | In short, it is suggested use a macro component if applicable (since it is easier), while using a composite component otherwise. | ||
=Implement a Composite Component= | =Implement a Composite Component= | ||
− | First, you have to decide which component to extend from. <javadoc>org.zkoss.zul.Div</javadoc> is a common choice since it is a simple component. | + | First, you have to decide which component to extend from. <javadoc>org.zkoss.zul.Div</javadoc> is a common choice since it is a simple component. However, here our example extends from <javadoc>org.zkoss.zul.Row</javadoc>, so it can be used under <javadoc>org.zkoss.zul.Rows</javadoc>, which the regular macros cannot. |
+ | |||
+ | Second, you have implement a template (in a ZUML document) to define what child components the composite component has. Then, you have to implement a Java class to put them together. | ||
==Implement a Template== | ==Implement a Template== | ||
+ | The implementation of a template is straightforward. There is nothing special to handle. Since it is rendered by <javadoc method="createComponents(java.lang.String, org.zkoss.zk.ui.Component, java.util.Map)">org.zkoss.zk.ui.Execution</javadoc>, you could pass whatever data you prefer to it (thru the <code>arg</code> argument). | ||
+ | |||
+ | Suppose we have a template as follows. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <zk> | ||
+ | Usename: <textbox id="mc_who"/> | ||
+ | </zk> | ||
+ | </source> | ||
+ | |||
==Implement a Java Class== | ==Implement a Java Class== | ||
===ID Space=== | ===ID Space=== |
Revision as of 03:43, 9 November 2010
Like a macro component, a composite component is an approach to compose a component based on a template. Unlike a macro component, a composite component has to create and wire the child components by itself, and handle ID space if necessary. The advantage is that a composite component can extend from any component, such as Row, such that it is easier to fit to any situation (and no need of the inline concept).
In short, it is suggested use a macro component if applicable (since it is easier), while using a composite component otherwise.
Implement a Composite Component
First, you have to decide which component to extend from. Div is a common choice since it is a simple component. However, here our example extends from Row, so it can be used under Rows, which the regular macros cannot.
Second, you have implement a template (in a ZUML document) to define what child components the composite component has. Then, you have to implement a Java class to put them together.
Implement a Template
The implementation of a template is straightforward. There is nothing special to handle. Since it is rendered by Execution.createComponents(String, Component, Map), you could pass whatever data you prefer to it (thru the arg
argument).
Suppose we have a template as follows.
<zk>
Usename: <textbox id="mc_who"/>
</zk>
Implement a Java Class
ID Space
Use Composite Component
Version History
Last Update : 2010/11/9
Version | Date | Content |
---|---|---|