Wire Components"

From Documentation
(more warning to usage.)
Line 2: Line 2:
  
  
Although the design principle of MVVM pattern is that '''ViewModel should not have any reference to UI components''', ZK still provides two ways to retrieve UI components in a ViewModel. <span style="color:#FF0000">'''We don't suggest this usage'''</span> because it loses the ViewModel an important advantage: loosely coupling with View. '''Notice that binder also manipulates UI components, so your operation to UI components might affect binder's work. Please be careful when using it.'''
+
Although the design principle of MVVM pattern is that '''ViewModel should not have any reference to UI components''', ZK still provides two ways to retrieve UI components in a ViewModel. We don't suggest this usage because it loses the ViewModel an important advantage: loosely coupling with View. '''Notice that binder also manipulates UI components, so your operation to UI components might affect binder's work. Please be careful when using it.'''
  
 
One way is [[ZK Developer's Reference/MVVM/Advance/Parameters |passing components as parameters in command binding]] which we have talked before. Another is to wire components by <tt> Selectors.wireComponents() </tt>. This way enables you to wire components with <tt> @Wire </tt> like [[ZK Developer's Reference/MVC/Controller/Wire Components| you do in a SelectorComposer]].  
 
One way is [[ZK Developer's Reference/MVVM/Advance/Parameters |passing components as parameters in command binding]] which we have talked before. Another is to wire components by <tt> Selectors.wireComponents() </tt>. This way enables you to wire components with <tt> @Wire </tt> like [[ZK Developer's Reference/MVC/Controller/Wire Components| you do in a SelectorComposer]].  

Revision as of 02:07, 29 May 2012


Although the design principle of MVVM pattern is that ViewModel should not have any reference to UI components, ZK still provides two ways to retrieve UI components in a ViewModel. We don't suggest this usage because it loses the ViewModel an important advantage: loosely coupling with View. Notice that binder also manipulates UI components, so your operation to UI components might affect binder's work. Please be careful when using it.

One way is passing components as parameters in command binding which we have talked before. Another is to wire components by Selectors.wireComponents() . This way enables you to wire components with @Wire like you do in a SelectorComposer.


Example to wire components in a ViewModel

public class SearchAutowireVM{

	//UI component
	@Wire("#msgPopup")
	Popup popup;
	@Wire("#msg")
	Label msg;

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

}
  • Selectors.wireComponents()'s first parameters is Root View Component which can be retrieved by @ContextParam


Version History

Last Update : 2012/05/29


Version Date Content
6.0.0 February 2012 The MVVM was introduced.




Last Update : 2012/05/29

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