import"
m |
|||
(11 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ZUMLReferencePageHeader}} | {{ZUMLReferencePageHeader}} | ||
− | + | <!-- implemented in org.zkoss.zk.ui.metainfo.Parser --> | |
− | '''Syntax | + | =Import Classes= |
− | + | '''Syntax''' | |
+ | <syntaxhighlight lang='xml'> | ||
+ | <?import ''class-name1'' ''class-name2'' ?> | ||
+ | </syntaxhighlight> | ||
− | + | {{versionSince| 6.0.0}} | |
It imports a class or a package of classes. It works like Java's import statement. For example, | It imports a class or a package of classes. It works like Java's import statement. For example, | ||
<source lang="xml"> | <source lang="xml"> | ||
− | <?import | + | <?import com.foo.composer.FooComposer?> |
− | <?import | + | <?import com.foo.init.*?> |
<?init class="FooInit"?><!-- it will look for com.foo.init.FooInit --> | <?init class="FooInit"?><!-- it will look for com.foo.init.FooInit --> | ||
Line 19: | Line 22: | ||
</source> | </source> | ||
− | + | {{versionSince| 8.0.0}} | |
− | |||
− | |||
− | + | After import, we can invoke the static method or field defined in imported class with el statement. For example, | |
− | A typical | + | <source lang="xml"> |
+ | <?import com.foo.FooClass ?> | ||
+ | <!-- or we can import com.foo.* --> | ||
+ | <label value="${FooClass.staticMethod()}"></label> | ||
+ | <label value="${FooClass.staticField}"></label> | ||
+ | </source> | ||
+ | |||
+ | = Import Directives= | ||
+ | '''Syntax to Import Directives''' | ||
+ | <syntaxhighlight lang='xml'> | ||
+ | <?import src="..."?> | ||
+ | <?import src="..." directives="..."?> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | It imports the directives, such as component definitions (<code><?component?></code>) and initiators (<code><?init?></code>), defined in another ZUML page. | ||
+ | |||
+ | A typical usage is that you put a set of component definitions on one ZUML page, and then import them into another ZUML page, such that both zul pages share the same set of component definitions, additional to the system default. | ||
<source lang="xml" > | <source lang="xml" > | ||
Line 34: | Line 51: | ||
</source> | </source> | ||
− | + | Where the <code>Special</code> class is assumed to be defined in <code>/WEB-INF/macros/special.zs</code>. | |
Then, other ZUML pages can share the same set of component definitions as follows. | Then, other ZUML pages can share the same set of component definitions as follows. | ||
<source lang="xml" > | <source lang="xml" > | ||
− | <?import | + | <?import src="special.zul"?> |
... | ... | ||
<special/><!-- you can use the component defined in special.zul --> | <special/><!-- you can use the component defined in special.zul --> | ||
Line 46: | Line 63: | ||
Notes | Notes | ||
− | * Unlike other directives, the import directives must be at the topmost level, i.e., at | + | * Unlike other directives, the import directives must be at the topmost level, i.e., at the same level as the root element. |
* The imported directives in the imported page are also imported. For example, if A imports B and B imports C, then A imports both C and B component definitions. If there is a name conflict, A overrides B, while B overrides C. | * The imported directives in the imported page are also imported. For example, if A imports B and B imports C, then A imports both C and B component definitions. If there is a name conflict, A overrides B, while B overrides C. | ||
− | * Once the directives are imported, they won't be changed until the importing page is | + | * Once the directives are imported, they won't be changed until the importing page is changed, no matter the imported page is changed or not. |
= class = | = class = | ||
[Required if importing a class] | [Required if importing a class] | ||
− | The name of a class, or a wildcard, such as < | + | The name of a class, or a wildcard, such as <code>com.foo.app.*</code>. |
− | = | + | = src = |
[Required if importing directives] | [Required if importing directives] | ||
Line 62: | Line 79: | ||
= directives = | = directives = | ||
[Optional] | [Optional] | ||
+ | default: component, init, import | ||
+ | |||
+ | If the <code>directives</code> attribute is omitted, only the <code>component</code>, <code>init</code> and <code>import</code> (with class) directives are imported. | ||
− | + | == Import specific directives== | |
+ | Specify a list of directive names separated by comma. For example, | ||
<source lang="xml" > | <source lang="xml" > | ||
− | <?import | + | <?import src="/template/taglibs.zul" directives="taglib, xel-method"?> |
− | <?import | + | <?import src="/template/java.zul" directives="import"?><!-- only <?import class="..."?> --> |
</source> | </source> | ||
− | The directives that can be imported include < | + | == Available values== |
+ | The directives that can be imported include | ||
+ | * <code>component</code> | ||
+ | * <code>header</code> | ||
+ | * <code>function-mapper</code> | ||
+ | * <code>import</code> | ||
+ | * <code>init</code> | ||
+ | * <code>meta</code>: include <code>meta</code>, <code>link</code> and <code>script</code> directives | ||
+ | * <code>taglib</code> | ||
+ | * <code>variable-resolver</code> | ||
+ | * <code>xel-method</code> | ||
+ | * <code>*</code>: import all above | ||
=Version History= | =Version History= | ||
Line 77: | Line 109: | ||
! Version !! Date !! Content | ! Version !! Date !! Content | ||
|- | |- | ||
− | | | + | | 6.0.0 |
| July, 2011 | | July, 2011 | ||
| The import of classes was introduced. | | The import of classes was introduced. |
Latest revision as of 03:44, 10 May 2022
Import Classes
Syntax
<?import ''class-name1'' ''class-name2'' ?>
Since 6.0.0
It imports a class or a package of classes. It works like Java's import statement. For example,
<?import com.foo.composer.FooComposer?>
<?import com.foo.init.*?>
<?init class="FooInit"?><!-- it will look for com.foo.init.FooInit -->
<window apply="FooComposer"><!-- com.foo.composer.FooComposer will be used -->
...
Since 8.0.0
After import, we can invoke the static method or field defined in imported class with el statement. For example,
<?import com.foo.FooClass ?>
<!-- or we can import com.foo.* -->
<label value="${FooClass.staticMethod()}"></label>
<label value="${FooClass.staticField}"></label>
Import Directives
Syntax to Import Directives
<?import src="..."?>
<?import src="..." directives="..."?>
It imports the directives, such as component definitions (<?component?>
) and initiators (<?init?>
), defined in another ZUML page.
A typical usage is that you put a set of component definitions on one ZUML page, and then import them into another ZUML page, such that both zul pages share the same set of component definitions, additional to the system default.
<!-- special.zul: Common Definitions -->
<?init zscript="/WEB-INF/macros/special.zs"?>
<?component name="special" macroURI="/WEB-INF/macros/special.zuml" class="Special"?>
<?component name="another" macroURI="/WEB-INF/macros/another.zuml"?>
Where the Special
class is assumed to be defined in /WEB-INF/macros/special.zs
.
Then, other ZUML pages can share the same set of component definitions as follows.
<?import src="special.zul"?>
...
<special/><!-- you can use the component defined in special.zul -->
Notes
- Unlike other directives, the import directives must be at the topmost level, i.e., at the same level as the root element.
- The imported directives in the imported page are also imported. For example, if A imports B and B imports C, then A imports both C and B component definitions. If there is a name conflict, A overrides B, while B overrides C.
- Once the directives are imported, they won't be changed until the importing page is changed, no matter the imported page is changed or not.
class
[Required if importing a class]
The name of a class, or a wildcard, such as com.foo.app.*
.
src
[Required if importing directives]
The URI of a ZUML page which the component definitions will be imported from.
directives
[Optional] default: component, init, import
If the directives
attribute is omitted, only the component
, init
and import
(with class) directives are imported.
Import specific directives
Specify a list of directive names separated by comma. For example,
<?import src="/template/taglibs.zul" directives="taglib, xel-method"?>
<?import src="/template/java.zul" directives="import"?><!-- only <?import class="..."?> -->
Available values
The directives that can be imported include
component
header
function-mapper
import
init
meta
: includemeta
,link
andscript
directivestaglib
variable-resolver
xel-method
*
: import all above
Version History
Version | Date | Content |
---|---|---|
6.0.0 | July, 2011 | The import of classes was introduced. |