Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  		Thu Nov 30 17:41:15     2006, Created by Henri Chen
 Copyright (C) 2006 Potix Corporation. All Rights Reserved.
 package org.zkoss.zkplus.databind;

This initiator class do following things:

  1. new an AnnotateDataBinder instance.
  2. set the AnnotateDataBinder instance as a variable with the name "binder" stored in the component as specified in arg0 "component-path".(if arg0 is not specified, use Page instead.)
  3. call DataBinder.loadAll() to initiate all UI components from the associated data bean.

Put the init PI as follows:

 <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" [arg0="component|component-path"] [arg1="true|false"]?>

Where the arg0 is the component itself (via EL expression) or the component path that specifies the component the AnnotateDataBinder covers. You can use absolute path that starts with "//" (search from Desktop) or "/" (search from Page); or you can use relative path(supported since ZK 3.0.8) that starts with "./" or "../" (relative to the Id Space of the root components of the zul page). If the arg0 is not specified or set to string "page", the AnnotateDataBinder will default to cover the whole page.

Where the arg1 is used to decide whether to load default binding configuration defined in lang-addon.xml. If the arg1 is not specified it is default to true. Note that you have to specify arg0 if you want to specify arg1.

Henri Chen
See also:
  public class AnnotateDataBinderInit implements InitiatorInitiatorExt {
 	private Component _comp;
 	private String _compPath;
 	private String _defaultConfig;

The AnnotateDataBinder created in doAfterCompose()
 	protected AnnotateDataBinder _binder
 	//-- Initator --//
 	public void doAfterCompose(Page page) {
 		//will not be called since we implements InitiatorExt
  	public boolean doCatch(java.lang.Throwable ex) {
  		return false// do nothing
 	public void doFinally() {
 		// do nothing
 	public void doInit(Page pagejava.lang.Object[] args) {
 		if (args.length > 0) {
 			Object arg0 = args[0];
 			if (arg0 instanceof String) {
 				 = (Stringarg0;
 			} else if (arg0 instanceof Component) {
 				 = (Componentarg0;
 			} else if (!(arg0 instanceof Page)) {
 				throw new UiException("arg0 has to be String, Component, or Page: "+arg0);
 		if (args.length > 1) {
 			 = (String)args[1];
 	//-- InitiatorExt --//
 	public void doAfterCompose(Page pageComponent[] compsthrows Exception {
 		boolean b =  != null ? Boolean.valueOf().booleanValue() : true;
 		if ( instanceof Component) { //a specified component instance
 		} else if ( == null || "page".equals()) { //page
 			 = new AnnotateDataBinder(pageb);
 			if (page.getVariable("binder") != null) { //already a binder on the page
 				throw new UiException("Page is already covered by another Data Binder. Cannot be covered by this Data Binder again. Page:"+page.getId());
 			} else {
else if (.startsWith("/")) { //absolute path
			final Component comp = Path.getComponent();
			if (comp == null) {
				throw new UiException("Cannot find the specified component. Absolute Path:"+);
			 = new AnnotateDataBinder(compb);
else if (.startsWith("./") || .startsWith("../")) { //relative path
			for (int j = 0; j < comps.length; ++j) {
				final Component vroot = comps[j];
				final Component comp = Path.getComponent(vroot.getSpaceOwner(), );
				if (comp != null) { //found
					 = new AnnotateDataBinder(compb);
			if ( == null) {
				throw new UiException("Cannot find the specified component. Relative Path:"+);
else {
			final Component comp = page.getFellow();
			 = new AnnotateDataBinder(compb);
		.loadAll(); //load data bean properties into UI components
New to GrepCode? Check out our FAQ X