@AfterCompose"

From Documentation
m
m ((via JWB))
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
 +
{{Deprecated | url=[http://books.zkoss.org/zk-mvvm-book/8.0/syntax/aftercompose.html zk-mvvm-book/8.0/syntax/viewmodel/aftercompose]|}}
  
(since 6.0.2)
 
  
 +
__TOC__
 +
since 6.0.2
 
=Syntax=
 
=Syntax=
 
<source lang="java">
 
<source lang="java">
Line 13: Line 15:
  
 
= Description =
 
= Description =
 +
 
'''Target:''' method, class  
 
'''Target:''' method, class  
  
'''Purpose:''' Marker annotation to identify a life-cycle method which will be invoked during <javadoc>org.zkoss.bind.BindComposer</javadoc>'s doAfterCompose invocation.  
+
'''Purpose:''' Marker annotation to identify a life cycle method which will be invoked in doAfterCompose() of <javadoc>org.zkoss.bind.BindComposer</javadoc>.
 
+
'.
'''Only one or none''' AfterCompose method is allowed in a ViewModel class. If you set annotation element '''superclass''' to '''true''', the ViewModel's parent class's ini method will be invoked first then child's, and this logic repeat on super class. If a class has no method with @AfterCompose, no method will be called (including the super class's)<ref>If you override parent class's AfterCompose method e.g. Parent.m1() <- Child.m1(). Because of Java's limitation, binder still call Child.m1(), and Child.m1() will be called twice. To avoid this, you should set superclass to false of Child.m1() and call super.m1() inside it.
+
'''Only one @AfterCompose-annotated method is allowed at the most''' in a ViewModel class. If you set annotation element '''superclass''' to '''true''', the ViewModel's parent class's @AfterCompose-annotated method will be invoked first then child's, and this logic repeats on super class. If a class has no method with @AfterCompose, no method will be called (including the super class's). <ref>If you override parent class's @AfterCompose-annotated method e.g. Parent.m1() <- Child.m1(). Because of Java's limitation, <javadoc>org.zkoss.bind.BindComposer</javadoc> still call Child.m1(), and Child.m1() will be called twice. To avoid this, you should set <code>superclass=false</code> for Child.m1() and call super.m1() inside it.
 
</ref>.
 
</ref>.
  
For example, in class hierarchy A(has AfterCompose) <- B(has AfterCompose) <- C(no AfterCompose) <- D (has AfterCompose, superclass true).  D is the last child class.
+
For example, in a class hierarchy: A(has @AfterCompose) <- B(has @AfterCompose) <- C(no @AfterCompose) <- D (has @AfterCompose, superclass=true).  D is the last child class.
* When bindComposer start to handle D while doAfterCompose, it will call D's AfterCompose method.
+
* When <javadoc>org.zkoss.bind.BindComposer</javadoc> start to handle D while in doAfterCompose(), it will call D's @AfterCompose method.
* When binder reaches C, no method will be called.
+
* When <javadoc>org.zkoss.bind.BindComposer</javadoc> reaches C, no method will be called.
* When binder reaches B , it will call As' then B's.  
+
* When <javadoc>org.zkoss.bind.BindComposer</javadoc> reaches B , it will call As' then B's.  
* When binder reaches A, it will call A's.
+
* When <javadoc>org.zkoss.bind.BindComposer</javadoc> reaches A, it will call A's.
  
 
We also can use parameter related annotation on AfterCompose method's parameters just as what we can do in @Init, please refer to subsections of [[ZK Developer's Reference/MVVM/Syntax/ViewModel/Parameters]].
 
We also can use parameter related annotation on AfterCompose method's parameters just as what we can do in @Init, please refer to subsections of [[ZK Developer's Reference/MVVM/Syntax/ViewModel/Parameters]].
Line 50: Line 53:
 
}
 
}
  
//since 6.0.2
 
 
@AfterCompose(superclass=true)
 
@AfterCompose(superclass=true)
 
public class ChildViewModel extends BarViewModel{
 
public class ChildViewModel extends BarViewModel{
Line 58: Line 60:
  
 
=Version History=
 
=Version History=
{{LastUpdated}}
+
 
{| border='1px' | width="100%"
+
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-
 
| 6.0.2
 
| 6.0.2
 
| June 2012
 
| June 2012
| The MVVM was introduced.
+
| The @AfterCompose was introduced.
 
|}
 
|}
  

Latest revision as of 07:35, 8 July 2022

Stop.png This article is out of date, please refer to zk-mvvm-book/8.0/syntax/viewmodel/aftercompose for more up to date information.


since 6.0.2

Syntax

@AfterCompose

@AfterCompose(superclass=true)

Description

Target: method, class

Purpose: Marker annotation to identify a life cycle method which will be invoked in doAfterCompose() of BindComposer. '. Only one @AfterCompose-annotated method is allowed at the most in a ViewModel class. If you set annotation element superclass to true, the ViewModel's parent class's @AfterCompose-annotated method will be invoked first then child's, and this logic repeats on super class. If a class has no method with @AfterCompose, no method will be called (including the super class's). [1].

For example, in a class hierarchy: A(has @AfterCompose) <- B(has @AfterCompose) <- C(no @AfterCompose) <- D (has @AfterCompose, superclass=true). D is the last child class.

  • When BindComposer start to handle D while in doAfterCompose(), it will call D's @AfterCompose method.
  • When BindComposer reaches C, no method will be called.
  • When BindComposer reaches B , it will call As' then B's.
  • When BindComposer reaches A, it will call A's.

We also can use parameter related annotation on AfterCompose method's parameters just as what we can do in @Init, please refer to subsections of ZK Developer's Reference/MVVM/Syntax/ViewModel/Parameters.


  1. If you override parent class's @AfterCompose-annotated method e.g. Parent.m1() <- Child.m1(). Because of Java's limitation, BindComposer still call Child.m1(), and Child.m1() will be called twice. To avoid this, you should set superclass=false for Child.m1() and call super.m1() inside it.

Example

public class FooViewModel{
	@AfterCompose
	public void doFoo(){
		//do while AfterCompose
	}
}

public class BarViewModel extends FooViewModel{
	@AfterCompose(superclass=true)
	public void afterComposeBar(){
		//AfterCompose method of super class FooViewModel will be called first.
	}
}

@AfterCompose(superclass=true)
public class ChildViewModel extends BarViewModel{

}

Version History

Version Date Content
6.0.2 June 2012 The @AfterCompose was introduced.




Last Update : 2022/07/08

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