Register as a TLD"

From Documentation
m (correct highlight (via JWB))
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{ZKSpreadsheetEssentialsPageHeader}}
 
{{ZKSpreadsheetEssentialsPageHeader}}
 +
 +
{{Deprecated|url=http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials}}
 +
  
 
__TOC__
 
__TOC__
 +
{{ZSS EE}}
  
 
ZK Spreadsheet allows developers to write their own custom formula functions. One way of implementing them is as a Java static method & declaring using xel-directive and another one is to implement it as EL function and register it in a TLD. Here we describe the second method.
 
ZK Spreadsheet allows developers to write their own custom formula functions. One way of implementing them is as a Java static method & declaring using xel-directive and another one is to implement it as EL function and register it in a TLD. Here we describe the second method.
Line 9: Line 13:
 
Define your custom formula function as an EL function. For example here is an EL function to convert USD to TWD.
 
Define your custom formula function as an EL function. For example here is an EL function to convert USD to TWD.
  
<source lang="java" high="3">
+
<source lang="java" highlight="3">
 
public class CurrencyFns {
 
public class CurrencyFns {
  
Line 18: Line 22:
 
</source>
 
</source>
 
===Register and config as a TLD===
 
===Register and config as a TLD===
Register above defined toTWD EL function in a TLD as shown below. <ref>More details on defining custom taglib to work with ZK please refer [http://books.zkoss.org/wiki/ZUML_Reference/ZUML/Processing_Instructions/taglib/Custom_Taglib here]</ref>
+
Register above defined toTWD EL function in a TLD as shown below. <ref>More details on defining custom taglib to work with ZK please refer [[ZUML_Reference/ZUML/Processing_Instructions/taglib/Custom_Taglib| here]]</ref>
<source lang="xml" high="3">
+
<source lang="xml" highlight="3">
 
<?xml version="1.0" encoding="UTF-8" ?>
 
<?xml version="1.0" encoding="UTF-8" ?>
 
<taglib>
 
<taglib>
<uri>http://www.zkoss.org/zss/example/custom</uri>
+
<uri>http://www.zkoss.org/zssessentials/example/custom</uri>
 
<description>
 
<description>
 
User defined functions.
 
User defined functions.
Line 28: Line 32:
 
<import>
 
<import>
 
<import-name>CurrencyFns</import-name>
 
<import-name>CurrencyFns</import-name>
<import-class>org.zkoss.zss.example.CurrencyFns</import-class>
+
<import-class>org.zkoss.zssessentials.functions.CurrencyFns</import-class>
 
</import>
 
</import>
  
 
<function>
 
<function>
 
<name>toTWD</name>
 
<name>toTWD</name>
<function-class>org.zkoss.zss.example.CurrencyFns
+
<function-class>org.zkoss.zssessentials.functions.CurrencyFns
 
</function-class>
 
</function-class>
 
<function-signature>double toTWD(double,double);</function-signature>
 
<function-signature>double toTWD(double,double);</function-signature>
 
<description>
 
<description>
Returns equivalent amount in TWD for the given amount in USD.
+
Returns equivalent amount in TWD for the given USD
 +
amount.
 
</description>
 
</description>
 
</function>
 
</function>
Line 47: Line 52:
 
<config>
 
<config>
 
<taglib>
 
<taglib>
<taglib-uri>http://www.zkoss.org/zss/example/custom</taglib-uri>
+
<taglib-uri>http://www.zkoss.org/zssessentials/example/custom</taglib-uri>
 
<taglib-location>/web/WEB-INF/tld/custom.tld</taglib-location>
 
<taglib-location>/web/WEB-INF/tld/custom.tld</taglib-location>
 
</taglib>
 
</taglib>
Line 53: Line 58:
 
</source>
 
</source>
 
==ZUML==
 
==ZUML==
To be able to use above defined toTWD EL Function as a custom ZK Spreadsheet formula fuction declare its registed TLD in your ZUL page using taglib directive [http://books.zkoss.org/wiki/ZK_ZUML_Reference/The_ZK_User_Interface_Markup_Language/Processing_Instructions/The_taglib_Directive].
+
To be able to use above defined toTWD EL Function as a custom ZK Spreadsheet formula fuction declare its registed TLD in your ZUL page using [[ZK_ZUML_Reference/The_ZK_User_Interface_Markup_Language/Processing_Instructions/The_taglib_Directive| the taglib directive]].
<source lang="xml" high="2">
+
<source lang="xml" highlight="2">
 
<?page title="ZSS" contentType="text/html;charset=UTF-8"?>
 
<?page title="ZSS" contentType="text/html;charset=UTF-8"?>
<?taglib uri="http://www.zkoss.org/zss/example/custom" prefix="zss" ?>
+
<?taglib uri="http://www.zkoss.org/zssessentials/example/custom" prefix="zss" ?>
 
<zk>
 
<zk>
<window title="ZSS User Defined Functions" border="normal" width="100%" height="100%">
+
<window title="ZSS User Defined Functions registered as a tld" border="normal" width="100%" height="100%">
 
<spreadsheet width="800px" height="800px"
 
<spreadsheet width="800px" height="800px"
src="/test2/xls/elfn.xlsx" maxrows="20" maxcolumns="10">
+
src="/WEB-INF/excel/functios/customfunctions.xlsx" maxrows="20" maxcolumns="10">
 
</spreadsheet>
 
</spreadsheet>
 
</window>
 
</window>
Line 67: Line 72:
 
'''Note''' that taglib ''prefix'' attribute value ''must'' be set to "'''zss'''" for ZK Spreadsheet to invoke implementation for such custom formula function.
 
'''Note''' that taglib ''prefix'' attribute value ''must'' be set to "'''zss'''" for ZK Spreadsheet to invoke implementation for such custom formula function.
  
===Using custom formula function in ZK Spreadsheet===
+
====Using custom formula function in ZK Spreadsheet====
  
 
Once defined and declared above custom formula function can be used just like any other built-in functions of Excel. Note that when entered in MS Excel it will result in #NAME? being displayed but when entered in ZK Spreadsheet it will we evaluated by invoking custom implementation declared through taglib directive.
 
Once defined and declared above custom formula function can be used just like any other built-in functions of Excel. Note that when entered in MS Excel it will result in #NAME? being displayed but when entered in ZK Spreadsheet it will we evaluated by invoking custom implementation declared through taglib directive.
Line 73: Line 78:
 
=toTWD(A1,B1)
 
=toTWD(A1,B1)
 
</source>
 
</source>
 +
 +
View complete source of ZUML [http://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/WebContent/functions/tldfunction.zul tldfunction.zul]
  
 
=Version History=
 
=Version History=

Latest revision as of 12:56, 19 January 2022


Stop.png This article is out of date, please refer to http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials for more up to date information.


Available in ZK Spreadsheet EE only

ZK Spreadsheet allows developers to write their own custom formula functions. One way of implementing them is as a Java static method & declaring using xel-directive and another one is to implement it as EL function and register it in a TLD. Here we describe the second method.

Purpose

Implement a custom formula function as an EL function and register it in a TLD.

Define EL function

Define your custom formula function as an EL function. For example here is an EL function to convert USD to TWD.

public class CurrencyFns {

	public static double toTWD(double usdNum, double twdRate) {
		return usdNum * twdRate;
	}
}

Register and config as a TLD

Register above defined toTWD EL function in a TLD as shown below. [1]

<?xml version="1.0" encoding="UTF-8" ?>
<taglib>
	<uri>http://www.zkoss.org/zssessentials/example/custom</uri>
	<description>
		User defined functions.
	</description>
	<import>
		<import-name>CurrencyFns</import-name>
		<import-class>org.zkoss.zssessentials.functions.CurrencyFns</import-class>
	</import>

	<function>
		<name>toTWD</name>
		<function-class>org.zkoss.zssessentials.functions.CurrencyFns
		</function-class>
		<function-signature>double toTWD(double,double);</function-signature>
		<description>
			Returns equivalent amount in TWD for the given USD
			amount.
		</description>
	</function>
</taglib>
  1. More details on defining custom taglib to work with ZK please refer here

Configure this TLD in /metainfo/tld/config.xml which can be find in the classpath. For example, you could put it under WEB-INF/classes/metainfo/tld/config.xml, or as part of a JAR file.

<config>
	<taglib>
		<taglib-uri>http://www.zkoss.org/zssessentials/example/custom</taglib-uri>
		<taglib-location>/web/WEB-INF/tld/custom.tld</taglib-location>
	</taglib>
</config>

ZUML

To be able to use above defined toTWD EL Function as a custom ZK Spreadsheet formula fuction declare its registed TLD in your ZUL page using the taglib directive.

<?page title="ZSS" contentType="text/html;charset=UTF-8"?>
<?taglib uri="http://www.zkoss.org/zssessentials/example/custom" prefix="zss" ?>
<zk>
	<window title="ZSS User Defined Functions registered as a tld" border="normal" width="100%" height="100%">
		<spreadsheet width="800px" height="800px"
			src="/WEB-INF/excel/functios/customfunctions.xlsx" maxrows="20" maxcolumns="10">
		</spreadsheet>
	</window>
</zk>

Note that taglib prefix attribute value must be set to "zss" for ZK Spreadsheet to invoke implementation for such custom formula function.

Using custom formula function in ZK Spreadsheet

Once defined and declared above custom formula function can be used just like any other built-in functions of Excel. Note that when entered in MS Excel it will result in #NAME? being displayed but when entered in ZK Spreadsheet it will we evaluated by invoking custom implementation declared through taglib directive.

=toTWD(A1,B1)

View complete source of ZUML tldfunction.zul

Version History

Last Update : 2022/01/19


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2022/01/19

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