Wire Event Listeners"

From Documentation
m ((via JWB))
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
 +
{{Deprecated | url=[http://books.zkoss.org/zk-mvvm-book/8.0/advanced/wire_event_listeners.html zk-mvvm-book/8.0/data_binding/advanced/wire_event_listeners]|}}
  
  
Line 5: Line 6:
  
  
To wire event listeners in a ViewModel like [[ZK Developer's Reference/MVC/Controller/Wire Event Listeners]], we have to call <tt> Selectors.wireEventListeners() </tt> in a method with <tt>@AfterCompose</tt>. We then can use <tt> @Listen</tt> to declare a method as an event listener.  '''We do not recommend this usage''' because it loses <b>ViewModel</b> an important advantage: loose coupling with View. '''Please evaluate the trade-offs before using it.'''
+
To wire event listeners in a ViewModel like [[ZK Developer's Reference/MVC/Controller/Wire Event Listeners]], we have to call <code>Selectors.wireEventListeners()</code> in a method with <code>@AfterCompose</code>. We then can use <code>@Listen</code> to declare a method as an event listener.  '''We do not recommend this usage''' because it loses <b>ViewModel</b> an important advantage: loose coupling with View. '''Please evaluate the trade-offs before using it.'''
  
  
 
''' Wire event listener in a ViewModel '''
 
''' Wire event listener in a ViewModel '''
<source lang="java" high="4,5,8">
+
<source lang="java" highlight="4,5,8">
  
 
public class SearchAutowireVM{
 
public class SearchAutowireVM{
Line 26: Line 27:
 
</source>
 
</source>
  
* <tt> Selectors.wireEventListeners()</tt> 's first parameters is Root View Component which can be retrieved by <tt>@ContextParam</tt>.
+
* <code>Selectors.wireEventListeners()</code> 's first parameters is Root View Component which can be retrieved by <code>@ContextParam</code>.
  
  
  
 
=Version History=
 
=Version History=
{{LastUpdated}}
+
 
{| border='1px' | width="100%"
+
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-

Latest revision as of 07:35, 8 July 2022


Wire Event Listeners


Stop.png This article is out of date, please refer to zk-mvvm-book/8.0/data_binding/advanced/wire_event_listeners for more up to date information.


since 6.0.2


To wire event listeners in a ViewModel like ZK Developer's Reference/MVC/Controller/Wire Event Listeners, we have to call Selectors.wireEventListeners() in a method with @AfterCompose. 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: loose coupling with View. Please evaluate the trade-offs before using it.


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

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




Last Update : 2022/07/08

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