Introduction

Any real-life web development environment needs a good 'data grid'. jZeno has a DynaTable component that allows you to visualize information in a grid. The main goals in creating the DynaTable were ease-of-use, and extensibility. The operation of the DynaTable can be tweaked in two major ways. Firstly, the columns are configured in terms of other dynamic components. This means that special requirement for visualizing information can allways be implemented, by creating a custom dynamic component. Secondly, the model that is used by the component when rendering information can be extended to implement various custom behaviour. We will discuss this technique later.

The DynaTable also has a couple of simple properties for tweaking the appearance of the grid. By default the DynaTable visualizes as a grid with a header, that allows sorting of the information in the table and allows paging the data being visualized if a lot of information is being displayed. Paging can be turned on and off as required, the header of the grid can also be hidden if required and the sort order of the columns can be configured. Rows in a DynaTable can also be selected (single/multi).

A DynaTable itself is databound like any other dynamic component, but the property path you bind to will have to be a java.util.Collection. All databinding specification of the columns in a DynaTable are done relative to the individual java beans in this collection. A DynaTable also supports editing of it's rows.


The Construction List

In order to specify which columns are to be visualized in the DynaTable a special helper class is used. This class is called the ConstructionList. It is used to specify for each column four things :

  1. The property path, relative to the individual java beans in the list our column viewer will be bound to.
  2. The header label to use for this column.
  3. The construction hints applied to cells of this column.
  4. Which type of viewer to use. This is done by specifying the java reflection API's Class instance.

A simple example to visualize address information :



package get.started;

public class Address {
	private static final long serialVersionUID = 1L;
	
	private String firstName = "";
	
	private String lastName = "";
	
	private String address = "";
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getFirstName() {
		return firstName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public String getLastName() {
		return lastName;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	public String getAddress() {
		return address;
	}	
}
	




package get.started;

import net.sf.jzeno.echo.components.Screen;
import net.sf.jzeno.echo.databinding.DynaTable;
import net.sf.jzeno.echo.viewer.StringViewer;

import java.util.List;
import java.util.ArrayList;

public class MyScreen extends Screen {
	private static final long serialVersionUID = 1L;
    
	private DynaTable dynaTable;
	
	private List list = new ArrayList();
	
	public MyScreen() {
		ConstructionList cl = new ConstructionList();
		cl.add("firstName","First Name","",StringViewer.class);
		cl.add("lastName","Last Name","",StringViewer.class);
		cl.add("address","Address","",StringViewer.class);
		dynaTable = new DynaTable(getClass(),"list","",cl);
		add(dynaTable);
		
		// ...
		// Initialize the list with some concrete 
                // instances of the Address bean
		// ...
	}
	
	public void setList(List list) {
		this.list = list;
	}
	
	public List getList() {
		return list;
	}
}
	


A DynaTable also has many properties to allow changing the appearance :


Extending the Model

Another way of adding flexibility to the possible uses of the DynaTable component, is setting you own model on the component. In general you may want to extend the existing BoundTableModel, or even override all methods to provide you own implementation. This is done by extending the BoundTableModel, overriding 1 or more methods (most likely the getValueAt() method) and setting an instance of your new class as the table model on the DynaTable by using setModel().



package get.started;

import net.sf.jzeno.echo.databinding.DynaTable;
import net.sf.jzeno.echo.databinding.BoundTableModel;

public class CustomModel extends BoundTableModel {
	public Object getValueAt(int row, int col) {
		Object ret = null;
		
		if(somecondition) {
			// Use the default behaviour of the bound table model...
			ret = super.getValueAt(row,col);
		} else {
			List list = getTable().getList();
			Object currentBean = list.get(row);
		
			ret = new MyCustomCellComponent();
			ret.setBean(currentBean);
			ret.setProperty("propertyToVisualize");
			ret.rebind();
		}
		
		return ret;
	}
}
	



Making a DynaTable Editable

DynaTables also support editing of the data. In order to use this you will need to specify not only classes for viewing your data in the ConstructionList, but also for editing the data. The ConstructionList has a special overloaded version of the add() method just for this. It accepts 7 arguments :

  1. The property path, relative to the individual java beans in the list our column's viewer will be bound to.
  2. The header label to use for this column.
  3. The construction hints applied to viewers of this column.
  4. The type of the viewer to use. This is done by specifying the java reflection API's Class instance.
  5. The property path, relative to the individual java beans in the list our column's editors will be bound to. (This may differ from the viewer's data binding)
  6. The construction hints applied to editors of this column.
  7. The type of the editor to use. This is done by specifying the java reflection API's Class instance.

Once you have created your DynaTable with this extended ConstructionList, you are able to use the folowing methods on the DynaTable to control editing :


Some More Tips