I'm working with Zk Framework. I know the existence of @AfterCompose and @Init annotations, but I don't know the differences and the order when I use it in a ViewModel.
Can someone explain the differences?
For example,
@AfterCompose
public void init(@ContextParam(ContextType.VIEW) Component view) {
Selectors.wireComponents(view, this, false); // wire the components here
}
@Init
public void init() {
//do more things
}
Thanks
The difference between @init and @AfterCompose is when they are executed but not what they will execute. These two methods work in a similar way to assign the variables in View Model and any other initialization tasks not dependent on component creation.
The ZUL Page Lifecycle is as follows:
1. Page initialization
2. Component creation
It first loads the properties of the Components assigned in ZUL
If any View Model assigned to the component using ViewModel attribute then it initilized by Binder and calls init method
If we mark some method as @init annotation then it will be called here.
When the component is created completely it calls AfterCompose
If we mark some method as @AfterCompose annotation then it will be called here.
3. Event Processing
4. Rendering
@init :
@AfterCompose :
Note : Using AfterCompose over init is recommended. Since it is called after the component creation and View Model initialization.
Please refer the below links for better understanding !!
https://www.zkoss.org/wiki/ZK_Developer%27s_Guide/Appendix/Component_Life_cycle/Table_of_Sequence
http://books.zkoss.org/zk-mvvm-book/8.0/syntax/viewmodelinit.html
http://books.zkoss.org/zk-mvvm-book/8.0/syntax/aftercompose.html