Initialization"
Jimmyshiau (talk | contribs) m (→Initial Method) |
Jimmyshiau (talk | contribs) |
||
Line 44: | Line 44: | ||
Since 6.0.1 | Since 6.0.1 | ||
− | If | + | If super has an init methold but its ChildViewModel doesn't, you can add <tt> @Init(superclass=true) </tt> on the ChildViewModel to use super's init. |
<source lang="java" high="6"> | <source lang="java" high="6"> | ||
public class ParentViewModel { | public class ParentViewModel { |
Revision as of 01:29, 17 January 2013
Initial Method
The binder is responsible for creating and initializing a ViewModel instance. If you want to perform your own initialization in a ViewModel, you can declare your own initial method by annotating a method with @Init . The Binder will invoke this method when initializing a ViewModel. Each ViewModel can only have one initial method.
public class MyViewModel {
@Init
public void init(){
//initialization code
}
}
This annotation has an attribute named "superclass", if you set it to "true". The binder will look for the initial method of ViewModel's parent class and invoke it first if it exists.
public class ParentViewModel{
@Init
public void init(){
//initialization code
}
}
public class ChildViewModel extends ParentViewModel{
@Init(superclass=true)
public void init(){
//initialization code
}
}
- ParentViewModel's initial method is invoked first then ChildViewModel's.
Apply on Class
Since 6.0.1
If super has an init methold but its ChildViewModel doesn't, you can add @Init(superclass=true) on the ChildViewModel to use super's init.
public class ParentViewModel {
@Init
public void init(){}
}
@Init(superclass=true)
public class ChildViewModel extends ParentViewModel{
}
The initial method can retrieve various context object by applying annotation on its parameter, please refer ZK Developer's Reference/MVVM/Advance/Parameters.
Version History
Version | Date | Content |
---|---|---|
6.0.0 | February 2012 | The MVVM was introduced. |