Pass Arguments to Include Component
From Documentation
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
Version | Date | Content |
---|---|---|
6.0.0 | February 2012 | The MVVM was introduced. |