@init"
m ((via JWB)) |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ZKDevelopersReferencePageHeader}} | {{ZKDevelopersReferencePageHeader}} | ||
+ | {{Deprecated | url=[http://books.zkoss.org/zk-mvvm-book/8.0/syntax/databindinginit.html zk-mvvm-book/8.0/syntax/data_binding/init]|}} | ||
=Syntax= | =Syntax= | ||
− | < | + | <code>@init(</code> ''[EvaluateOnce EL-expression], [arbitraryKey]=[EL-expression] '' <code>)</code> |
= Description = | = Description = | ||
Line 17: | Line 18: | ||
For other attributes, binder initializes their value with EL evaluation result. | For other attributes, binder initializes their value with EL evaluation result. | ||
− | When using on "viewModel" attribute, we can pass arguments in key-value pairs with comma separated. And we can get the arguments in a initial method of ViewModel by < | + | When using on "viewModel" attribute, we can pass arguments in key-value pairs with comma separated. And we can get the arguments in a initial method of ViewModel by <code>[[ZK_Developer%27s_Reference/MVVM/Syntax/ViewModel/Parameters/@BindingParam| @BindingParam]]</code>. |
;''[arbitraryKey]=[EL-expression]'' | ;''[arbitraryKey]=[EL-expression]'' | ||
Line 44: | Line 45: | ||
</source> | </source> | ||
+ | |||
'''Pass arguments''' | '''Pass arguments''' | ||
− | <source lang="xml" | + | <source lang="xml" highlight='2'> |
<window width="400px" apply="org.zkoss.bind.BindComposer" | <window width="400px" apply="org.zkoss.bind.BindComposer" | ||
viewModel="@id('vm') @init('org.zkoss.reference.developer.mvvm.databinding.InitVM', arg1='myValue')"> | viewModel="@id('vm') @init('org.zkoss.reference.developer.mvvm.databinding.InitVM', arg1='myValue')"> | ||
Line 53: | Line 55: | ||
</source> | </source> | ||
− | + | <source lang="java" highlight='4'> | |
− | <source lang="java" | ||
public class InitVM { | public class InitVM { | ||
Line 65: | Line 66: | ||
=Version History= | =Version History= | ||
− | + | ||
− | {| | + | {| class='wikitable' | width="100%" |
! Version !! Date !! Content | ! Version !! Date !! Content | ||
|- | |- |
Latest revision as of 07:35, 8 July 2022
This article is out of date, please refer to zk-mvvm-book/8.0/syntax/data_binding/init for more up to date information.
Syntax
@init(
[EvaluateOnce EL-expression], [arbitraryKey]=[EL-expression] )
Description
Target Attribute: any
Purpose: Initialize an attribute's value and no reload during user interaction.
The EL expression in this annotation is only evaluated once when binder parses it. When you use it on "viewModel" attribute, binder will try to resolve the EL expression as a class and create an instance of it.
In "form" attribute, the result of evaluating the EL expression should be a Form object.
For other attributes, binder initializes their value with EL evaluation result.
When using on "viewModel" attribute, we can pass arguments in key-value pairs with comma separated. And we can get the arguments in a initial method of ViewModel by @BindingParam
.
- [arbitraryKey]=[EL-expression]
- It's key-value pairs basically. You can write multiple key-value pairs with different key names.
- An EL expression without key is set to a default key named "value" implicitly.
- Due to each annotation has different functions, some annotations may ignore key-value pair expression other than default key, e.g.@id.
- [arbitraryKey]
- It could be any name, it's used as a key for parameter related Java annotation in a ViewModel.
Example
Usage example in viewModel attribute
<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('foo.ChildrenMenuVM')" >
</window>
Usage example in form attribute
<vbox form="@id('fx') @init(vm.myForm) @load(vm.person) @save(vm.person, before='save')">
</vbox>
Pass arguments
<window width="400px" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('org.zkoss.reference.developer.mvvm.databinding.InitVM', arg1='myValue')">
...
</window>
public class InitVM {
@Init
public void init(@BindingParam("arg1") String arg1){
System.out.println("arg1: "+arg1);
}
}
Version History
Version | Date | Content |
---|---|---|
6.0.0 | February 2012 | The MVVM was introduced. |