HtmlMacroComponent"
Jumperchen (talk | contribs) |
|||
(9 intermediate revisions by 6 users not shown) | |||
Line 4: | Line 4: | ||
*Demonstration: N/A | *Demonstration: N/A | ||
− | *Java API: <javadoc>org.zkoss.zk.ui. | + | *Java API: <javadoc>org.zkoss.zk.ui.HtmlMacroComponent</javadoc> |
*JavaScript API: N/A | *JavaScript API: N/A | ||
Line 11: | Line 11: | ||
The base class for macro components. | The base class for macro components. | ||
− | If you want to apply the auto-wiring, you can invoke <javadoc method="wireVariables(org.zkoss.zk.ui.Component, java.lang.Object)">org.zkoss.zk.ui.Components</javadoc> in <javadoc method="afterCompose()">org.zkoss.zk.ui.HtmlMacroComponent</javadoc> as follows. | + | {{versionSince | 5.0.4}} By default invoking <javadoc method="afterCompose()">org.zkoss.zk.ui.HtmlMacroComponent</javadoc> supports auto forward events and wire accessible variables to this component. |
+ | |||
+ | For example, (usemacro.zul) | ||
+ | <source lang="xml"> | ||
+ | <?init zscript="macro.zs"?> | ||
+ | <?component name="username" macroURI="macro.zul" class="Username"?> | ||
+ | <window id="wnd"> | ||
+ | <username id="ua"/> | ||
+ | <username label="Account"/> | ||
+ | </window> | ||
+ | </source> | ||
+ | |||
+ | (macro.zs) | ||
+ | <source lang="java"> | ||
+ | import org.zkoss.zk.ui.*; | ||
+ | import org.zkoss.zul.*; | ||
+ | |||
+ | public class Username extends HtmlMacroComponent { | ||
+ | Button btn; // auto wire | ||
+ | |||
+ | // auto forward | ||
+ | public void onClick$btn () { | ||
+ | System.out.println("success... and btn varible is not null : " + (btn != null)); | ||
+ | } | ||
+ | }; | ||
+ | </source> | ||
+ | |||
+ | (macro.zul) | ||
+ | <source lang="xml"> | ||
+ | <grid id="mc_grid"> | ||
+ | <rows> | ||
+ | <row id="r"> | ||
+ | <button label="${empty arg.label ? 'Username': arg.label}" id="btn"/> | ||
+ | </row> | ||
+ | </rows> | ||
+ | </grid> | ||
+ | </source> | ||
+ | |||
+ | If you want to turn off the auto wiring mechanism, please refer to the following steps: | ||
+ | |||
+ | Turn off auto wire mechanism by specifying the Library Property "org.zkoss.zk.ui.macro.autowire.disabled" to "true" in WEB-INF/zk.xml. If you did not specify the Library Property, the default is false. | ||
+ | <source lang="xml"><library-property> | ||
+ | <name>org.zkoss.zk.ui.macro.autowire.disabled</name> | ||
+ | <value>true</value> | ||
+ | </library-property></source> | ||
+ | or turn off auto forward events by specifying the Library Property "org.zkoss.zk.ui.macro.autoforward.disabled" to "true" in WEB-INF/zk.xml. If you did not specify the Library Property, the default is false. | ||
+ | <source lang="xml"><library-property> | ||
+ | <name>org.zkoss.zk.ui.macro.autoforward.disabled</name> | ||
+ | <value>true</value> | ||
+ | </library-property></source> | ||
+ | |||
+ | |||
+ | In the early version, if you want to apply the auto-wiring, you can invoke <javadoc method="wireVariables(org.zkoss.zk.ui.Component, java.lang.Object)">org.zkoss.zk.ui.Components</javadoc> in <javadoc method="afterCompose()">org.zkoss.zk.ui.HtmlMacroComponent</javadoc> as follows. | ||
<source lang="java"> | <source lang="java"> | ||
Line 28: | Line 80: | ||
=Supported Events= | =Supported Events= | ||
− | {| | + | {| class='wikitable' | width="100%" |
! <center>Name</center> | ! <center>Name</center> | ||
! <center>Event Type</center> | ! <center>Event Type</center> | ||
Line 45: | Line 97: | ||
=Use cases= | =Use cases= | ||
− | {| | + | {| class='wikitable' | width="100%" |
! Version !! Description !! Example Location | ! Version !! Description !! Example Location | ||
|- | |- | ||
Line 55: | Line 107: | ||
= Version History = | = Version History = | ||
− | {| | + | {| class='wikitable' | width="100%" |
! Version !! Date !! Content | ! Version !! Date !! Content | ||
|- | |- | ||
− | | | + | | 5.0.3 |
− | | | + | | June 2010 |
− | | | + | | The corresponding DOM element is customizable. It defaults to SPAN (the same as prior version) but you can change it to any tag by use of <javadoc method="setEnclosingTag(java.lang.String)">org.zkoss.zk.ui.HtmlMacroComponent</javadoc>. |
+ | |- | ||
+ | | 5.0.4 | ||
+ | | August 2010 | ||
+ | | By default, invoking <javadoc method="afterCompose()">org.zkoss.zk.ui.HtmlMacroComponent</javadoc> supports auto forward events and wire accessible variables to this component. | ||
|} | |} | ||
{{ZKComponentReferencePageFooter}} | {{ZKComponentReferencePageFooter}} |
Latest revision as of 07:14, 6 March 2024
Html Macro Component
- Demonstration: N/A
- Java API: HtmlMacroComponent
- JavaScript API: N/A
Employment/Purpose
The base class for macro components.
Since 5.0.4 By default invoking HtmlMacroComponent.afterCompose() supports auto forward events and wire accessible variables to this component.
For example, (usemacro.zul)
<?init zscript="macro.zs"?>
<?component name="username" macroURI="macro.zul" class="Username"?>
<window id="wnd">
<username id="ua"/>
<username label="Account"/>
</window>
(macro.zs)
import org.zkoss.zk.ui.*;
import org.zkoss.zul.*;
public class Username extends HtmlMacroComponent {
Button btn; // auto wire
// auto forward
public void onClick$btn () {
System.out.println("success... and btn varible is not null : " + (btn != null));
}
};
(macro.zul)
<grid id="mc_grid">
<rows>
<row id="r">
<button label="${empty arg.label ? 'Username': arg.label}" id="btn"/>
</row>
</rows>
</grid>
If you want to turn off the auto wiring mechanism, please refer to the following steps:
Turn off auto wire mechanism by specifying the Library Property "org.zkoss.zk.ui.macro.autowire.disabled" to "true" in WEB-INF/zk.xml. If you did not specify the Library Property, the default is false.
<library-property>
<name>org.zkoss.zk.ui.macro.autowire.disabled</name>
<value>true</value>
</library-property>
or turn off auto forward events by specifying the Library Property "org.zkoss.zk.ui.macro.autoforward.disabled" to "true" in WEB-INF/zk.xml. If you did not specify the Library Property, the default is false.
<library-property>
<name>org.zkoss.zk.ui.macro.autoforward.disabled</name>
<value>true</value>
</library-property>
In the early version, if you want to apply the auto-wiring, you can invoke Components.wireVariables(Component, Object) in HtmlMacroComponent.afterCompose() as follows.
public void afterCompose() {
super.afterCompose(); //create components
Components.wireVariables(this, this);
Components.addForward(this, this);
}
Example
N/A
Supported Events
None | None |
See also events inherited from HtmlBasedComponent's Supported Events.
Supported Children
*ALL
Use cases
Version | Description | Example Location |
---|---|---|
Version History
Version | Date | Content |
---|---|---|
5.0.3 | June 2010 | The corresponding DOM element is customizable. It defaults to SPAN (the same as prior version) but you can change it to any tag by use of HtmlMacroComponent.setEnclosingTag(String). |
5.0.4 | August 2010 | By default, invoking HtmlMacroComponent.afterCompose() supports auto forward events and wire accessible variables to this component. |