Actions and Effects"

From Documentation
Line 15: Line 15:
 
To apply the client-side action to a widget, you have to assign a value to the <code>action</code> property (<javadoc method="setAction(java.lang.String)">org.zkoss.zk.ui.HtmlBasedComponent</javadoc>). The syntax of the value is as follows.
 
To apply the client-side action to a widget, you have to assign a value to the <code>action</code> property (<javadoc method="setAction(java.lang.String)">org.zkoss.zk.ui.HtmlBasedComponent</javadoc>). The syntax of the value is as follows.
  
  ''action-name1'': ''action-effect1''; ''action-name2'': ''action-effect2''
+
  ''action-name1'': ''effect1''; ''action-name2'': ''effect2''
  
The action name (e.g., <code>action1</code>) has to be one of the predefined names, such as show and hide. The action effect (e.g., <code>action-effect1</code>) has to be one of the predefined effects, such as slideDown and slideUp.
+
The action name (e.g., <code>action1</code>) has to be one of the predefined names, such as show and hide. The action effect (e.g., <code>effect1</code>) has to be one of the predefined effects, such as slideDown and slideUp.
  
 
For example, we could use the ''slide-down'' effect to display a window as follows.
 
For example, we could use the ''slide-down'' effect to display a window as follows.
Line 30: Line 30:
 
</zk></source>
 
</zk></source>
  
== Available Actions ==
+
In additions, you could specify additions options by enclosing it with the parentheses as follows.
== Available Effects ==
+
 
 +
<source lang="xml">
 +
<div action="show: slideDown({duration: 1000}); hide: slideUp({duration: 300})">
 +
....
 +
</div>
 +
</source>
 +
 
 +
which specifies the duration of sliding down is 100 milliseconds, and the duration of sliding-up is 300 milliseconds.
 +
 
 +
Security Note: the options is actually a JavaScript object (i.e., a map, <javadoc directory="jsdoc">_global_.Map</javadoc>), and ZK pass whatever being specified to the client for evaluation. Thus, if you allow the user to specify the effect, you shall encode it first to avoid [[ZK Developer's Reference/Security Tips/Cross-site scripting|cross-site scripting]].
 +
== Predefined Actions ==
 +
 
 +
Here is a list of predefined actions.
 +
== Predefined Effects ==
 +
Here is a list of predefined actions.
  
 
= Notes for Upgrading from ZK 3 =
 
= Notes for Upgrading from ZK 3 =

Revision as of 06:06, 27 December 2010


Actions and Effects


[since 5.0.6]

The client-side action (CSA) is used to control how to perform an action at the client. Typical use is to control the effect of showing or hiding a widget. For example, with CSA, you could use the so-called slide-down effect to display a widget.

It is a generic feature available to HtmlBasedComponent, so you could apply to almost all widgets.

CSA allows the developer to control some actions without JavaScript. If you want to have the full control (and are OK to write some JavaScript code), please refer to ZK Client-side Reference for the complete control of the client-side behavior.

How to Apply CSA

To apply the client-side action to a widget, you have to assign a value to the action property (HtmlBasedComponent.setAction(String)). The syntax of the value is as follows.

action-name1: effect1; action-name2: effect2

The action name (e.g., action1) has to be one of the predefined names, such as show and hide. The action effect (e.g., effect1) has to be one of the predefined effects, such as slideDown and slideUp.

For example, we could use the slide-down effect to display a window as follows.

<zk>
	<button label="Show a modal window" onClick="wnd.doModal()"/>
	<window id="wnd" title="Modal" border="normal"
	 action="show: slideDown" visible="false">
		This is a modal window.
	</window>
</zk>

In additions, you could specify additions options by enclosing it with the parentheses as follows.

<div action="show: slideDown({duration: 1000}); hide: slideUp({duration: 300})">
....
</div>

which specifies the duration of sliding down is 100 milliseconds, and the duration of sliding-up is 300 milliseconds.

Security Note: the options is actually a JavaScript object (i.e., a map, Map), and ZK pass whatever being specified to the client for evaluation. Thus, if you allow the user to specify the effect, you shall encode it first to avoid cross-site scripting.

Predefined Actions

Here is a list of predefined actions.

Predefined Effects

Here is a list of predefined actions.

Notes for Upgrading from ZK 3

They are both called Client-side Actions, but they are different and you have to rewrite them to make it work under ZK 5:

  1. The action names was changed and the support is limited to show and hide (while ZK 3 supports any onxxx).
  2. The action operation is the name of the method in Actions (while ZK 3 is the JavaScript code).
  3. It is part of HtmlBasedComponent (while ZK 3 is XulElement).

Version History

Last Update : 2010/12/27


Version Date Content
5.0.6 December 2010 Actions were introduced since 5.0.6



Last Update : 2010/12/27

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