Pass Arguments to Include Component"

From Documentation
(copy from "MVVM>Advance>Access Arguments")
 
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
When you load a ZUL page using <tt> Executions.createComponents("mypage.zul", args) </tt> or  <tt> <include> </tt> and pass arguments. ZK bind annotation EL expression can not reference those arguments directly. The simplest solution is to add an custom attribute to hold arguments for later reference. Let's see an example.
+
When you load a ZUL page using <tt> Executions.createComponents("mypage.zul", args) </tt> or  <tt> <include> </tt> and pass arguments. ZK bind annotation EL expression can not reference those arguments directly because of life cycle issue. What a binder performs is a post-processing action after components creation. At the moment of post-processing, it cannot obtain arguments.  The simplest solution is to add an custom attribute to hold arguments for later reference. Let's see an example.
  
 
'''outer.zul'''
 
'''outer.zul'''
Line 14: Line 14:
 
'''inner.zul'''
 
'''inner.zul'''
  
<source lang="xml" high="1,5">
+
<source lang="xml" high="2,6">
 
+
<zk>
 
<custom-attributes type="${arg.type}"/>
 
<custom-attributes type="${arg.type}"/>
 
<vbox apply="org.zkoss.bind.BindComposer"
 
<vbox apply="org.zkoss.bind.BindComposer"
Line 22: Line 22:
 
<button id="cmd1" label="cmd1" onClick="@command('cmd1', mytype=type)" />
 
<button id="cmd1" label="cmd1" onClick="@command('cmd1', mytype=type)" />
 
</vbox>
 
</vbox>
 +
</zk>
 
</source>
 
</source>
 
* We should use a custom attribute (line 1) to hold the argument for later use (line 5).
 
* We should use a custom attribute (line 1) to hold the argument for later use (line 5).
 +
 +
 +
== Arguments from ViewModel ==
 +
 +
If an argument comes from a ViewModel's property, "src" attribute must also load with data binding and be specified at last attribute for life cycle issue.
 +
 +
<source lang="xml">
 +
 +
<include type="@load(vm.myArgument)" src="@load(vm.innerZul)"/>
 +
 +
</source>
 +
* For fixed page, you can specify <tt>@load('inner.zul')</tt>.
 +
  
  

Revision as of 07:34, 24 December 2012


DocumentationZK Developer's ReferenceMVVMAdvancedPass Arguments to Include Component
Pass Arguments to Include Component


When you load a ZUL page using Executions.createComponents("mypage.zul", args) or <include> and pass arguments. ZK bind annotation EL expression can not reference those arguments directly because of life cycle issue. What a binder performs is a post-processing action after components creation. At the moment of post-processing, it cannot obtain arguments. The simplest solution is to add an custom attribute to hold arguments for later reference. Let's see an example.

outer.zul

<include id="inc" type="typeValue" src="inner.zul"/>
  • Here we pass an argument named "type" to an included ZUL.

inner.zul

<zk>
	<custom-attributes type="${arg.type}"/>
	<vbox apply="org.zkoss.bind.BindComposer"
		viewModel="@id('vm') @init('foo.ExecutionParamVM')">
		
		<button id="cmd1" label="cmd1" onClick="@command('cmd1', mytype=type)" />
	</vbox>
</zk>
  • We should use a custom attribute (line 1) to hold the argument for later use (line 5).


Arguments from ViewModel

If an argument comes from a ViewModel's property, "src" attribute must also load with data binding and be specified at last attribute for life cycle issue.

<include type="@load(vm.myArgument)" src="@load(vm.innerZul)"/>
  • For fixed page, you can specify @load('inner.zul').



Version History

Last Update : 2012/12/24


Version Date Content
6.0.0 February 2012 The MVVM was introduced.




Last Update : 2012/12/24

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