Wire Event Listeners"

From Documentation
m
Line 13: Line 13:
 
@Init
 
@Init
 
public void init(@ContextParam(ContextType.VIEW) Component view){
 
public void init(@ContextParam(ContextType.VIEW) Component view){
 +
Selectors.wireEventListeners(view, this);
 +
}
 +
 +
@Listen("onClick=#mybutton")
 +
public void submit(MouseEvent event){
 +
//handle events
 +
}
 +
}
 +
 +
</source>
 +
 +
* <tt> Selectors.wireEventListeners()</tt> 's first parameters is Root View Component which can be retrieved by <tt>@ContextParam</tt>.
 +
 +
= Usage Changed in 6.0.2 =
 +
 +
The timing of <tt> BindComposer </tt> calling @Init method becomes earlier to handle more common situation. Hence, to wire components in a ViewModel, you should use <tt> @AfterCompose </tt> as follows:
 +
 +
''' Wire event listener in a ViewModel '''
 +
<source lang="java" high="4,5,8">
 +
 +
public class SearchAutowireVM{
 +
 +
@AfterCompose
 +
public void afterCompose(@ContextParam(ContextType.VIEW) Component view){
 
Selectors.wireEventListeners(view, this);
 
Selectors.wireEventListeners(view, this);
 
}
 
}
Line 36: Line 60:
 
| May 2012
 
| May 2012
 
| Supplement
 
| Supplement
 +
|-
 +
| 6.0.2
 +
| July 2012
 +
| The @AfterCompose was introduced.
 
|}
 
|}
  

Revision as of 07:45, 10 July 2012


Wire Event Listeners



To wire event listeners in a ViewModel like ZK Developer's Reference/MVC/Controller/Wire Event Listeners, we have to call Selectors.wireEventListeners() in the initial method. We then can use @Listen to declare a method as an event listener. We do not recommend this usage because it loses ViewModel an important advantage i.e. loose coupling with View. Please evaluate the trade-offs before using it.


Wire event listener in a ViewModel

public class SearchAutowireVM{

	@Init
	public void init(@ContextParam(ContextType.VIEW) Component view){
		Selectors.wireEventListeners(view, this);
	}

	@Listen("onClick=#mybutton")
	public void submit(MouseEvent event){
		//handle events
	}
}
  • Selectors.wireEventListeners() 's first parameters is Root View Component which can be retrieved by @ContextParam.

Usage Changed in 6.0.2

The timing of BindComposer calling @Init method becomes earlier to handle more common situation. Hence, to wire components in a ViewModel, you should use @AfterCompose as follows:

Wire event listener in a ViewModel

public class SearchAutowireVM{

	@AfterCompose
	public void afterCompose(@ContextParam(ContextType.VIEW) Component view){
		Selectors.wireEventListeners(view, this);
	}

	@Listen("onClick=#mybutton")
	public void submit(MouseEvent event){
		//handle events
	}
}
  • Selectors.wireEventListeners() 's first parameters is Root View Component which can be retrieved by @ContextParam.


Version History

Last Update : 2012/07/10


Version Date Content
6.0.0 May 2012 Supplement
6.0.2 July 2012 The @AfterCompose was introduced.




Last Update : 2012/07/10

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