Useful Java Utilities"
m (ZK-4372: Extract Notification functionalities from Clients) |
(Toast) |
||
Line 113: | Line 113: | ||
Clients.showNotification("msg1 <br/> msg2 <br/>"); | Clients.showNotification("msg1 <br/> msg2 <br/>"); | ||
</source> | </source> | ||
+ | |||
+ | ==showToast== | ||
+ | [since 9.0.0] | ||
+ | [http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/util/Clients.html#showToast(java.lang.String) Clients.showToast()] | ||
+ | |||
+ | It's an alias of <code>Toast.show</code>. Please refer to Toast section for details. | ||
=Notification= | =Notification= | ||
Line 124: | Line 130: | ||
Notification.show(msg); // display a global notification box | Notification.show(msg); // display a global notification box | ||
Notification.show(msg, component); // display a notification box pointing to a component | Notification.show(msg, component); // display a notification box pointing to a component | ||
+ | </source> | ||
+ | |||
+ | =Toast= | ||
+ | [since 9.0.0] | ||
+ | |||
+ | [http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/util/Toast.html org.zkoss.zk.ui.util.Toast] | ||
+ | |||
+ | This class offers a collection of methods showing a toast notification, which is dismissed upon left click (like Popup). Unlike Notification, Toast is stackable. | ||
+ | |||
+ | <source lang="java"> | ||
+ | Toast.show(msg); // display a toast notification | ||
+ | Toast.show(msg, "warning", "top_right"); // display a toast notification on top-right of the browser viewport | ||
+ | </source> | ||
+ | |||
+ | You can also specify its position, style, duration (for auto-dismiss) and closable: | ||
+ | |||
+ | <source lang="java"> | ||
+ | Toast.show(msg, type, position, duration, closable); | ||
+ | </source> | ||
+ | |||
+ | Here are the available positions: | ||
+ | {| border='1px' | width="100%" | ||
+ | ! !! left !! center !! right | ||
+ | |- | ||
+ | | <b>top</b> | ||
+ | | top_left | ||
+ | | top_center | ||
+ | | top_right | ||
+ | |- | ||
+ | | <b>middle</b> | ||
+ | | middle_left | ||
+ | | middle_center | ||
+ | | middle_right | ||
+ | |- | ||
+ | | <b>bottom</b> | ||
+ | | bottom_left | ||
+ | | bottom_center | ||
+ | | bottom_right | ||
+ | |} | ||
+ | |||
+ | ==Animation Speed== | ||
+ | |||
+ | To specify the duration of opening and closing animation, [https://www.zkoss.org/wiki/ZK_Configuration_Reference/zk.xml/The_Library_Properties/org.zkoss.zk.ui.util.Toast.animationSpeed org.zkoss.zk.ui.util.Toast.animationSpeed] is provided. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <library-property> | ||
+ | <name>org.zkoss.zk.ui.util.Toast.animationSpeed</name> | ||
+ | <value>500</value> | ||
+ | </library-property> | ||
</source> | </source> | ||
Line 138: | Line 193: | ||
| July 2012 | | July 2012 | ||
| [http://tracker.zkoss.org/browse/ZK-1145 ZK-1145]: Notification supports closable | | [http://tracker.zkoss.org/browse/ZK-1145 ZK-1145]: Notification supports closable | ||
+ | |- | ||
+ | | 9.0.0 | ||
+ | | Sep 2019 | ||
+ | | [http://tracker.zkoss.org/browse/ZK-4371 ZK-4371]: Provide a Toast utility | ||
|- | |- | ||
| 9.0.0 | | 9.0.0 |
Revision as of 03:31, 19 September 2019
In this section we introduce some of the most commonly used Java utility classes.
Executions
getCurrent
Retrieves the current execution (request/response).
createComponents
With this method, you can create components defined in another zul file and attach them to the current page.
sendRedirect
Redirects to another URL. If the parameter is left null, it will redirect to the current page.
Sessions
getCurrent
Retrieves the current session.
Clients
This class offers a collection of methods which manipulate client side via AU Response.
evalJavaScript
This method sends an AU Response to execute the given JavaScript on client side, which is the standard way of calling JavaScript from server side in ZK. For example,
Clients.evalJavaScript("zk.log('Hi.');");
scrollIntoView
Clients.scrollIntoView(Component cmp)
Scrolls the parent of the given component, so the given one become visible in the view.
showBusy/clearBusy
Display/dismiss a busy icon, so user knows server is working or has finished working on something. For example,
Clients.showBusy(window, "Waiting for server...");
showNotification
[since 6.0.1]
[since 9.0.0]
It is advised to use Notification class which was introduced in ZK 9 instead.
Show a notification box, which is dismissed upon left click (like Popup). You can either display a global notification (bigger) or one specific to another component (smaller with an arrow pointing to it).
Clients.showNotification(msg); // display a global notification box
Clients.showNotification(msg, component); // display a notification box pointing to a component
You can also specify its position, style, and duration (for auto-dismiss):
Clients.showNotification(msg, type, component, position, duration);
Type determines the style of the notification box.
Here are the available positions:
Closable
[since 6.5.0]
Notification now supports closable to let user close the notification box manually.
// add close icon on the top right corner of notification box
Clients.showNotification(msg, closable);
Multiline
To show a multiline message, just append
in the message string.
Clients.showNotification("msg1 <br/> msg2 <br/>");
showToast
[since 9.0.0]
It's an alias of Toast.show
. Please refer to Toast section for details.
Notification
[since 9.0.0]
org.zkoss.zk.ui.util.Notification
This class offers a collection of methods showing a notification box, which is dismissed upon left click (like Popup). You can either display a global notification (bigger) or one specific to another component (smaller with an arrow pointing to it).
Notification.show(msg); // display a global notification box
Notification.show(msg, component); // display a notification box pointing to a component
Toast
[since 9.0.0]
This class offers a collection of methods showing a toast notification, which is dismissed upon left click (like Popup). Unlike Notification, Toast is stackable.
Toast.show(msg); // display a toast notification
Toast.show(msg, "warning", "top_right"); // display a toast notification on top-right of the browser viewport
You can also specify its position, style, duration (for auto-dismiss) and closable:
Toast.show(msg, type, position, duration, closable);
Here are the available positions:
left | center | right | |
---|---|---|---|
top | top_left | top_center | top_right |
middle | middle_left | middle_center | middle_right |
bottom | bottom_left | bottom_center | bottom_right |
Animation Speed
To specify the duration of opening and closing animation, org.zkoss.zk.ui.util.Toast.animationSpeed is provided.
<library-property>
<name>org.zkoss.zk.ui.util.Toast.animationSpeed</name>
<value>500</value>
</library-property>
Version History
Version | Date | Content |
---|---|---|
6.0.1 | March 2012 | Add Clients.showNotification() |
6.5.0 | July 2012 | ZK-1145: Notification supports closable |
9.0.0 | Sep 2019 | ZK-4371: Provide a Toast utility |
9.0.0 | Sep 2019 | ZK-4372: Extract Notification functionalities from Clients |