Pass Arguments to Include Component

From Documentation
Revision as of 07:34, 24 December 2012 by Hawk (talk | contribs)


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.