Using a ListModel and RowRenderer"

From Documentation
Line 4: Line 4:
  
 
===Where the View, Model, and Renderer Come Together===
 
===Where the View, Model, and Renderer Come Together===
To associate the View with a Model and Renderer, we'll implement a controller class which extends a ZK utility class  <javadoc>org.zkoss.zk.ui.util.GenericForwardComposer</javadoc>. In its <javadoc method="doAfterCompose(org.zkoss.zk.ui.Component)">org.zkoss.zk.ui.util.GenericForwardComposer</javadoc> method, the ZK components declared in mark up are wired with the component instances declared in the controller for our manipulation, while the events fired are automatically forwarded to this controller for event handling. Hence, we override and call <javadoc method="doAfterCompose(org.zkoss.zk.ui.Component)">org.zkoss.zk.ui.util.GenericForwardComposer</javadoc> method of its super class and implement the code that assigns a model and renderer to our "Product View" Grid.
+
To associate our Product View (Grid component) with a Model and a Renderer, we'll implement a controller class which extends the ZK utility class  <javadoc>org.zkoss.zk.ui.util.GenericForwardComposer</javadoc>. In its <javadoc method="doAfterCompose(org.zkoss.zk.ui.Component)">org.zkoss.zk.ui.util.GenericForwardComposer</javadoc> method, the ZK components declared in mark up are wired with the component instances declared in the controller for our manipulation, while the events fired are automatically forwarded to this controller for event handling. Therefore, in our controller class, we override and call <javadoc method="doAfterCompose(org.zkoss.zk.ui.Component)">org.zkoss.zk.ui.util.GenericForwardComposer</javadoc> method of its super class and implement the code that assigns a model and renderer to our Product View Grid.<br>
 +
'''ProductViewCtrl.java'''
 
<source lang="java">
 
<source lang="java">
 
public class ProductViewCtrl extends GenericForwardComposer {
 
public class ProductViewCtrl extends GenericForwardComposer {
Line 15: Line 16:
 
 
 
//create model
 
//create model
                //assign model to Grid
+
        //assign model to Grid
+
 
                //create renderer
+
//create renderer
                //assign renderer to Grid
+
        //assign renderer to Grid
 
 
 
}
 
}
 
}
 
}
 
</source>
 
</source>
 +
 
===Wrapping Data Object with ListModel===
 
===Wrapping Data Object with ListModel===

Revision as of 02:14, 13 October 2010

Stop.png This article is out of date, please refer to http://books.zkoss.org/zkessentials-book/master/ for more up to date information.

Using a ListModel and RowRenderer

Data presentation in ZK involves preparing the Model and Renderer in association with the View (ZK components). Once an association is established between these three parts, the data presented in ZK components are automatically updated whenever the data model is changed. In the previous section, we declared the basic UI skeleton, now we'll look into how to prepare a data model and write a renderer to populate the Grid component.

Where the View, Model, and Renderer Come Together

To associate our Product View (Grid component) with a Model and a Renderer, we'll implement a controller class which extends the ZK utility class GenericForwardComposer. In its GenericForwardComposer.doAfterCompose(Component) method, the ZK components declared in mark up are wired with the component instances declared in the controller for our manipulation, while the events fired are automatically forwarded to this controller for event handling. Therefore, in our controller class, we override and call GenericForwardComposer.doAfterCompose(Component) method of its super class and implement the code that assigns a model and renderer to our Product View Grid.
ProductViewCtrl.java

public class ProductViewCtrl extends GenericForwardComposer {

	private Grid prodGrid;
	
 	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		
		//create model
        //assign model to Grid

		//create renderer
        //assign renderer to Grid
		
	}
}

Wrapping Data Object with ListModel