Wire Components"

From Documentation
m
(no need to call Selectors.wireVariables() in init method)
Line 2: Line 2:
  
  
Although the original design principle of MVVM pattern is that ViewModel doesn't have any reference to UI components, ZK provide ways to retrieve UI components on a ZUL in a ViewModel. One is passing components as parameters in binding expression. Another is to wire components by Selector. This way enables you to wire components with <tt> @Wire </tt> like you do in a <javadoc> org.zkoss.zk.ui.select.SelectorComposer</javadoc>. Before doing this, you have to call <tt> Selectors.wireComponents() </tt> manually and pass the root component in initial method.
+
Although the original design principle of MVVM pattern is that ViewModel doesn't have any reference to UI components, ZK provide ways to retrieve UI components on a ZUL in a ViewModel. One is passing components as parameters in binding expression. Another is to wire components by Selector. This way enables you to wire components with <tt> @Wire </tt> like you do in a <javadoc> org.zkoss.zk.ui.select.SelectorComposer</javadoc>.  
  
 
'''Example to wire components in a ViewModel'''
 
'''Example to wire components in a ViewModel'''
Line 14: Line 14:
 
Label msg;
 
Label msg;
  
@Init
 
public void init(@ContextParam(ContextType.VIEW) Component view){
 
Selectors.wireComponents(view, this, false);
 
}
 
 
}
 
}
  

Revision as of 05:00, 25 April 2012


Although the original design principle of MVVM pattern is that ViewModel doesn't have any reference to UI components, ZK provide ways to retrieve UI components on a ZUL in a ViewModel. One is passing components as parameters in binding expression. Another is to wire components by Selector. 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;

}
  • Use @ContextParam(ContextType.VIEW) to retrieve root component. (line 11)


Version History

Last Update : 2012/04/25


Version Date Content
6.0.0 February 2012 The MVVM was introduced.




Last Update : 2012/04/25

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