Initialization"

From Documentation
m
(upward -> superclass)
Line 16: Line 16:
 
</source>
 
</source>
  
This annotation has an element "upward", 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.
+
This annotation has an element "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.
  
 
<source lang="java">
 
<source lang="java">
Line 31: Line 31:
 
public class ChildViewModel extends ParentViewModel{
 
public class ChildViewModel extends ParentViewModel{
  
@Init(upward=true)
+
@Init(superclass=true)
 
public void init(){
 
public void init(){
 
//initialization code
 
//initialization code

Revision as of 04:16, 10 February 2012


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 element "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.

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

Last Update : 2012/02/10


Version Date Content
6.0.0 February 2012 The MVVM was introduced.



Last Update : 2012/02/10

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