Integrate ZK Spreadsheet with Spring

From Documentation
Revision as of 06:10, 7 December 2010 by Char (talk | contribs) (→‎Introduction)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
DocumentationSmall Talks2008MayIntegrate ZK Spreadsheet with Spring
Integrate ZK Spreadsheet with Spring

Ivan Cheng, Engineer, Potix Corporation
May 6, 2008
Applicable to ZK 3.0.5 and later
Applicable to ZK Spreadsheet 1.0.0 and later


In Use JavaBean in Excel with ZK Spreadsheet and Change the Style of Spreadsheet within 1 Min , we demonstrate how to use JavaBean directly via Variable-Resolver and change the style of spreadsheet with ease. In this article, we will integrate ZK Spreadsheet and Spring to achieve same functionality. It is easy to integrate ZK Spreadsheet with Spring.

If you'd like to know more about ZK Spreadsheet, please refer to the following URLs:

If you'd like to know more about Variable-Resolver, please refer to the following URL:

Let's start to build an application for integrating ZK Spreadsheet and Spring.

Live Demo

It is similar to the demo in previous article. It demonstrates that you can achieve same functionality by integrating ZK Spreadsheet with Spring.

Configuration Files

In your web.xml, you have to use org.springframework.web.context.ContextLoaderListener to load the spring configuration when the server started.





Define your bean in Spring's configuration file. Please remember the bean id (dataBean, database) which will be taken as a key for Variable-Resolver to lookup the bean. I will describe it later.



	<bean id="dataBean" class="model.DataBean"/>
	<bean id="database" class="model.Database">
		<property name="dataBean">
			<ref bean="dataBean"/>


Get Values via Variable-Resolver

ZK provides a variable-resolver directive that application developers can specifies the resolver class that will be used by the zscript interpreter to resolve unknown variables. Based on such mechanism, the ZK Team has implemented a variable resolver class that would automatically resolve the Spring bean objects by their ids defined in spring-config.xml . Thus the zul page now can use the Spring beans seamlessly in zscript or EL expression just like using general ZK components.


//Add Variable-Resolver for Spring
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
  <listbox id="quarter" mold="select" rows="1" onSelect="refreshQuarter()">
	<listitem value="0" label="Select"/>
	<listitem value="1" label="Quarter 1"/>
	<listitem value="2" label="Quarter 2"/>
	<listitem value="3" label="Quarter 3"/>
	<listitem value="4" label="Quarter 4"/>
  <listbox id="style" mold="select" rows="1" onSelect="changeStyle()">
	<listitem label="Style 1" value="/BalanceSheet.xls"/>
	<listitem label="Style 2" value="/NewSheet.xls"/>
	void refreshQuarter() {
		Listitem listitem = quarter.getSelectedItem();
		int quarter = Integer.parseInt(listitem.value);
		//Call the method to reload data
		//Call the method to refresh values of cells String[]{"dataBean"});
	void changeStyle() {  //Change the URL of spreadsheet
		balance.url = style.getSelectedItem().value;
	//Initial data, ZK will find it via DelegatingVariableResolver.
	<spreadsheet id="balance" url="/BalanceSheet.xls" maxrow="40" maxcolumn="20" height="600px" width="1300px"/> 



The ZK team has implemented a Spring bean variable resolver which allows accessing spring bean directly in zscript and EL expression. In the same way we can get Spring beans in ZK Spreadsheet. All we have to do is to modify configuration files and then, layout the Spreadsheet at proper place. In the near future, we will introduce more useful tools of ZK Spreadsheet. We expect your response to make it better, feel free to leave a message or post it to ZK forum .

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