Integrate ZK Spreadsheet with Spring

From Documentation
Revision as of 02:57, 23 November 2010 by Henrichen (talk | contribs) (Created page with 'ZK Spreadsheet can resolve the name expressions in cells to bind the data from the Spring-managed beans automatically. ===purpose=== Data binding spreadsheet cells to Spring-man…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ZK Spreadsheet can resolve the name expressions in cells to bind the data from the Spring-managed beans automatically.


Data binding spreadsheet cells to Spring-managed beans.

Integrate ZK Spreadsheet with Spring

As we have mentioned in How ZK Spreadsheet Resolve my Java Beans, ZK Spreadsheet follows ZK's EL expression variable resolving mechanism. When trying to resolve a variable, it will finally ask variable resolvers declared in the ZUML page to retrieve the bean of the named variable. So simply declare the variable-resolver with org.zkoss.zkplus.spring.DelegatingVariableResolver on top of your ZUML page, you are now data-binding your ZK Spreadsheet with your Spring-managed beans directly. Following we demonstrate the example that use the same bsheet.xls template file as in Template Excel File with Proper Name Expressions but data-binding to Spring-managed bean.


In ZUML page, we declare the variable resolver for retrieving Spring-Managed beans so ZK Spreadsheet can find them and show the evaluated value in the spreadsheet's cells.

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<spreadsheet id="bsheet"

Spring Configuration File

Define bean definitions in applicationContext.xml file, and put it into your WEB-INF directory.

<?xml version="1.0" encoding="UTF-8"?>
  <bean id="dataBean" class="demo.springbean.DataBeanImpl"/>

Spring Bean

Define DataBean interface and its implementation. Mainly getters and setters for various attributes for a balance sheet.

package demo.springbean;
public interface DataBean {
	public double getLiquidAssets();

	public void setLiquidAssets(double liquidAssets);

	//...other getters and setters

package demo.springbean;
public class DataBeanImpl implements DataBean {
	private double liquidAssets;
	private double fundInvestment;
	private double fixedAssets;
	private double intangibleAsset; 
	private double otherAssets;
	private double currentLiabilities;
	private double longTermLiabilities;
	private double otherLiabilities;
	private double capitalStock;
	private double capitalSurplus;
	private double retainedEarnings;
	private double otherEquity;
	private double treasuryStock;
	public double getLiquidAssets() {
		return liquidAssets;

	public void setLiquidAssets(double liquidAssets) {
		this.liquidAssets = liquidAssets;

	//...other getters and setters implementation