init"

From Documentation
m
m (correct highlight (via JWB))
 
(8 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
__TOC__
 
__TOC__
  
<source lang="xml" >
+
'''Syntax:'''
 
  <?init class="..." [''arg0''="..."] [''arg1''="..."] [''arg2''="..."] [''arg3''="..."]?>
 
  <?init class="..." [''arg0''="..."] [''arg1''="..."] [''arg2''="..."] [''arg3''="..."]?>
 
  <?init zscript="..."?>
 
  <?init zscript="..."?>
</source>
 
  
There are two formats. The first format is to specify a class that is used to do the application-specific initialization. The second format is to specify a <tt>zscript</tt> file to do the application-specific initialization.
+
It defines an initiator that will be instantiated and called when the ZUML document is loaded.
 +
 
 +
There are two formats. The first format is to specify a class that is used to do the application-specific initialization. The second format is to specify a <code>zscript</code> file to do the application-specific initialization.
  
The initialization takes place before the page is evaluated and attached to a desktop. Thus, the <tt>getDesktop</tt>, <tt>getId</tt> and <tt>getTitle</tt> method will return null, when initializing. To retrieve the current desktop, you could use the <javadoc type="interface">org.zkoss.zk.ui.Execution</javadoc> interface.
+
The initialization takes place before the page is evaluated and attached to a desktop. Thus, the <code>getDesktop</code>, <code>getId</code> and <code>getTitle</code> method will return null when initializing. To retrieve the current desktop, you could use <javadoc type="interface">org.zkoss.zk.ui.Execution</javadoc>.
  
You could specify any number of the <tt>init</tt> directive. The specified class must implement the <javadoc type="interface">org.zkoss.zk.ui.util.Initiator</javadoc> interface.
+
You could specify any number of the <code>init</code> directive. The specified class must implement the <javadoc type="interface">org.zkoss.zk.ui.util.Initiator</javadoc> interface.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 19: Line 20:
 
</source>
 
</source>
  
Since 3.6.2, you can use any (readable) name instead of <tt>arg0</tt> and so on. For example,
+
Since 3.6.2, you can use any (readable) name instead of <code>arg0</code> and so on. For example,
  
 
<source lang="xml">
 
<source lang="xml">
Line 25: Line 26:
 
</source>
 
</source>
  
== class ==
+
Then, <javadoc method="doInit(org.zkoss.zk.ui.Page, java.util.Map)" type="interface">org.zkoss.zk.ui.util.Initiator</javadoc> will be called with a map, which contains an entry, whose name is <code>root</code> and value <code>./abc</code>.
 +
 
 +
If you'd like to apply an initiator for every page, you don't need to specify it on every page. Rather, you could install a system-level initiator. For more information, please refer to [[ZK Developer's Reference/UI Patterns/Page Initialization#System-level_Initiator|ZK Developer's Reference: System-level Initiators]].
  
<source lang="xml" >
+
= class =
[Optional]
+
 
</source>
+
[Optional]
  
A class name that must implement the <javadoc type="interface">org.zkoss.zk.ui.util.Initiator</javadoc> interface. Unlike the <tt>init</tt> directive, the class name cannot be the class that is defined in zscript codes.
+
A class name must implement the <javadoc type="interface">org.zkoss.zk.ui.util.Initiator</javadoc> interface. Unlike the <code>init</code> directive, the class name cannot be the class that is defined in zscript codes.
  
An instance of the specified class is constructed and its <tt>doInit</tt> method is called in the Page Initial phase (i.e., before the page is evaluated). The <tt>doFinally</tt> method is called after the page has been evaluated. The <tt>doCatch</tt> method is called if an exception occurs during the evaluation.
+
An instance of the specified class is constructed and its <code>doInit</code> method is called in the Page Initial phase (i.e., before the page is evaluated). The <code>doFinally</code> method is called after the page has been evaluated. The <code>doCatch</code> method is called if an exception occurs during the evaluation.
  
 
Thus, you could also use it for cleanup and error handling.
 
Thus, you could also use it for cleanup and error handling.
  
== zscript ==
+
= zscript =
  
<source lang="xml" >
+
[Optional]
[Optional]
 
</source>
 
  
A <tt>script</tt> file that will be evaluated in the Page Initial phase.
+
A <code>script</code> file that will be evaluated in the Page Initial phase.
  
== arg0, arg1... ==
+
= arg0, arg1... =
  
<source lang="xml" >
+
[Optional]
[Optional]
 
</source>
 
  
You could specify any number of arguments. It will be passed to the <tt>doInit</tt> method if the first format is used. Since 3.6.2, you can use any name for the arguments, but, in the prior version, the first argument is <tt>arg0</tt>, the second is <tt>arg1</tt> and follows.
+
You could specify any number of arguments. It will be passed to the <code>doInit</code> method if the first format is used. Since 3.6.2, you can use any name for the arguments, but, in the prior version, the first argument must be named as <code>arg0</code>, the second is <code>arg1</code> and so on.
  
==Version History==
+
=Version History=
  
 
{| border='1px' | width="100%"
 
{| border='1px' | width="100%"

Latest revision as of 13:28, 19 January 2022

Syntax:

<?init class="..." [arg0="..."] [arg1="..."] [arg2="..."] [arg3="..."]?>
<?init zscript="..."?>

It defines an initiator that will be instantiated and called when the ZUML document is loaded.

There are two formats. The first format is to specify a class that is used to do the application-specific initialization. The second format is to specify a zscript file to do the application-specific initialization.

The initialization takes place before the page is evaluated and attached to a desktop. Thus, the getDesktop, getId and getTitle method will return null when initializing. To retrieve the current desktop, you could use Execution.

You could specify any number of the init directive. The specified class must implement the Initiator interface.

 <?init class="MyInit1"?>
 <?init class="MyInit2"?>

Since 3.6.2, you can use any (readable) name instead of arg0 and so on. For example,

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./abc"?>

Then, Initiator.doInit(Page, Map) will be called with a map, which contains an entry, whose name is root and value ./abc.

If you'd like to apply an initiator for every page, you don't need to specify it on every page. Rather, you could install a system-level initiator. For more information, please refer to ZK Developer's Reference: System-level Initiators.

class

[Optional]

A class name must implement the Initiator interface. Unlike the init directive, the class name cannot be the class that is defined in zscript codes.

An instance of the specified class is constructed and its doInit method is called in the Page Initial phase (i.e., before the page is evaluated). The doFinally method is called after the page has been evaluated. The doCatch method is called if an exception occurs during the evaluation.

Thus, you could also use it for cleanup and error handling.

zscript

[Optional]

A script file that will be evaluated in the Page Initial phase.

arg0, arg1...

[Optional]

You could specify any number of arguments. It will be passed to the doInit method if the first format is used. Since 3.6.2, you can use any name for the arguments, but, in the prior version, the first argument must be named as arg0, the second is arg1 and so on.

Version History

Version Date Content
     



Last Update : 2022/01/19

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