public class Clients
extends java.lang.Object
AuResponse
to the client.
Utilities here are mainly to control how the client (a.k.a., the browser window)
behaves. To get the status, you might refer to ClientInfoEvent
.
Note: this class makes accessing 'client-side' more directly.
Methods such as showBusy(String)
or showNotification(String)
will not encode the strings passed into them,
thus the formatting of messages at 'client-side' is allowed.
User input should be escaped carefully especially when using evalJavaScript(String)
to execute dynamically concatenated JavaScript code.
ClientInfoEvent
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NOTIFICATION_TYPE_ERROR
Notification type: error
|
static java.lang.String |
NOTIFICATION_TYPE_INFO
Notification type: information
|
static java.lang.String |
NOTIFICATION_TYPE_WARNING
Notification type: warning
|
Constructor and Description |
---|
Clients() |
Modifier and Type | Method and Description |
---|---|
static void |
alert(java.lang.String msg)
Shows an error message at the browser.
|
static void |
alert(java.lang.String msg,
java.lang.String title,
java.lang.String icon)
Shows an error message at the browser.
|
static void |
clearBusy()
Cleans the busy message at the browser.
|
static void |
clearBusy(Component comp)
Clears the busy message at the browser that covers only the specified
component.
|
static void |
clearWrongValue(Component comp)
Closes the error message of the specified component, if any,
at the browser.
|
static void |
clearWrongValue(Component[] comps)
Closes the error message of the specified components, if any,
at the browser.
|
static void |
clearWrongValue(java.util.List<Component> comps)
Closes the error message of the specified components, if any,
at the browser.
|
static void |
confirmClose(java.lang.String mesg)
Asks a browser to confirm users whether to leave the current page.
|
static void |
evalJavaScript(java.lang.String javaScript)
Asks the browser to evaluate the specified JavaScript.
|
static void |
focus(Component component)
Focus the component (HtmlBasedComponent)
|
static void |
focus(java.lang.String selector)
Focus the first matching component (HtmlBasedComponent) by using selector
Note: The Selector will locate the components in the first page of current Desktop.
|
static void |
loadCSS(java.lang.String url)
Loads a CSS file.
|
static void |
loadScript(java.lang.String url)
Loads a JavaScript file to client and execute it.
|
static void |
loadScript(java.lang.String url,
java.lang.String callback,
boolean cache)
Loads a JavaScript file to client and execute it.
|
static void |
log(java.lang.Object msg)
Logs the message to the client.
|
static void |
log(java.lang.String msg)
Logs the message to the client.
|
static void |
moveBy(int x,
int y)
Moves the current desktop (a.k.a., browser window) by the specified number of pixels.
|
static void |
moveTo(int x,
int y)
Moves the current desktop (a.k.a., browser window) to the specified location (in pixels).
|
static void |
print()
Asks the client to print the current desktop (a.k.a., browser window).
|
static void |
reloadMessages(java.util.Locale locale)
Reloads the client-side messages in the specified locale.
|
static void |
resize(Component comp)
Forces the client to re-calculate the size of the given component.
|
static void |
resizeBy(int x,
int y)
Resizes the current desktop (a.k.a., browser window) by the specified number of pixels.
|
static void |
resizeTo(int x,
int y)
Resizes the current desktop (a.k.a., browser window) to the specified size (in pixels).
|
static void |
response(AuResponse response)
Sends an AU response (
AuResponse ) to the client. |
static void |
response(java.lang.String key,
AuResponse response)
Sends an AU response (
AuResponse ) to the client
with the given key (instead of AuResponse.getOverrideKey() ). |
static void |
scrollBy(int x,
int y)
Scrolls the current desktop (a.k.a., browser window) by the specified number of pixels.
|
static void |
scrollIntoView(Component cmp)
Scrolls the ancestor elements to make the specified element visible.
|
static void |
scrollIntoView(java.lang.String selector)
Scrolls the ancestor elements to make the selector matched element visible
Note: The Selector will locate the components in the first page of current Desktop.
|
static void |
scrollTo(int x,
int y)
Scrolls the current desktop (a.k.a., browser window) to the specified location (in pixels).
|
static void |
sendClientCommand(Component component,
java.lang.String commandName,
java.lang.Object data)
Send a command to client (afterCommand)
|
static void |
showBusy(Component comp,
java.lang.String msg)
Shows the busy message at the browser that covers only the specified
component.
|
static void |
showBusy(java.lang.String msg)
Shows the busy message at the browser such that
the user knows the system is busy.
|
static void |
showNotification(java.lang.String msg)
Shows a message at the center of the browser window.
|
static void |
showNotification(java.lang.String msg,
boolean closable)
Shows a message at the center of the browser window.
|
static void |
showNotification(java.lang.String msg,
Component ref)
Shows a message at the right side of the given component.
|
static void |
showNotification(java.lang.String msg,
Component ref,
boolean closable)
Shows a message at the right side of the given component.
|
static void |
showNotification(java.lang.String msg,
java.lang.String type,
Component ref,
int x,
int y,
int duration)
Displays a message.
|
static void |
showNotification(java.lang.String msg,
java.lang.String type,
Component ref,
int x,
int y,
int duration,
boolean closable)
Displays a message.
|
static void |
showNotification(java.lang.String msg,
java.lang.String type,
Component ref,
java.lang.String position,
int duration)
Displays a message.
|
static void |
showNotification(java.lang.String msg,
java.lang.String type,
Component ref,
java.lang.String position,
int duration,
boolean closable)
Displays a message.
|
static void |
submitForm(Component form)
Submits the form with the specified form.
|
static void |
submitForm(java.lang.String formId)
Submits the form with the specified ID.
|
static void |
syncErrorbox()
Send a command to sync all the errorboxes and its reference component position on the desktop.
|
static void |
syncErrorbox(Component component)
Send a command to sync a target component and its errorbox position.
|
static void |
wrongValue(Component comp,
java.lang.String msg)
Shows an error message for the specified component, if any,
at the browser.
|
public static final java.lang.String NOTIFICATION_TYPE_INFO
public static final java.lang.String NOTIFICATION_TYPE_WARNING
public static final java.lang.String NOTIFICATION_TYPE_ERROR
public static final void response(AuResponse response)
AuResponse
) to the client.
It is the same as response(response.getOverrideKey(), response)
.public static final void response(java.lang.String key, AuResponse response)
AuResponse
) to the client
with the given key (instead of AuResponse.getOverrideKey()
).key
- could be anything. The second invocation of this method
in the same execution with the same key will override the previous one.
In other words, the previous one will be dropped.
If null is specified, the response is simply appended to the end
without overriding any previous one.response(org.zkoss.zk.au.AuResponse)
public static final void confirmClose(java.lang.String mesg)
If a non-null (non-empty) string is passed, a browser will show up its own confirmation dialog when a user tries to reload, close, or leave the current page. To disable showing any confirmation dialog, just call this method again with null. Check MDN for more info.
mesg
- all major browsers don't support showing a custom message. Pass a non-empty string to enable the confirmation dialog.
If null (default) or empty, users can close the browser window directly.public static final void alert(java.lang.String msg)
Messagebox
.
However, it is not customizable (at the server), but it is
much faster and light-weighted.public static final void alert(java.lang.String msg, java.lang.String title, java.lang.String icon)
Messagebox
.msg
- the message to display.title
- the title of the message boxicon
- the icon to show. It could null,
"QUESTION", "EXCLAMATION", "INFORMATION", "ERROR", "NONE".
If null, "ERROR" is assumedpublic static final void wrongValue(Component comp, java.lang.String msg)
You have to clear the error message manually with clearWrongValue(org.zkoss.zk.ui.Component)
.
public static final void clearWrongValue(Component comp)
public static final void clearWrongValue(java.util.List<Component> comps)
public static final void clearWrongValue(Component[] comps)
public static final void submitForm(java.lang.String formId)
public static final void submitForm(Component form)
public static void print()
public static final void scrollIntoView(Component cmp)
public static final void scrollIntoView(java.lang.String selector)
selector
- the selector stringSelectors.find(org.zkoss.zk.ui.Page, String)
,
Selectors.find(Component, String)
public static final void scrollBy(int x, int y)
scrollTo(int, int)
public static final void scrollTo(int x, int y)
scrollBy(int, int)
public static final void resizeBy(int x, int y)
resizeTo(int, int)
public static final void resizeTo(int x, int y)
resizeBy(int, int)
public static final void moveBy(int x, int y)
moveTo(int, int)
public static final void moveTo(int x, int y)
moveBy(int, int)
public static final void evalJavaScript(java.lang.String javaScript)
It has no effect if the client doesn't support JavaScript.
javaScript
- the javaScript codes to run at the browserpublic static final void showNotification(java.lang.String msg)
msg
- the message to showNotification.show(String)
public static final void showNotification(java.lang.String msg, boolean closable)
msg
- the message to showclosable
- whether to close notification manually or not. If true there will be a
close button on notification message and won't close until user click the button
or duration time up, default false.Notification.show(String, boolean)
public static final void showNotification(java.lang.String msg, Component ref)
msg
- the message to showref
- the referenced component, null to be based on browser windowNotification.show(String, Component)
public static final void showNotification(java.lang.String msg, Component ref, boolean closable)
msg
- the message to showref
- the referenced component, null to be based on browser windowclosable
- whether to close notification manually or not. If true there will be a
close button on notification message and won't close until user click the button
or duration time up, default false.Notification.show(String, Component, boolean)
public static final void showNotification(java.lang.String msg, java.lang.String type, Component ref, java.lang.String position, int duration)
msg
- the message to showtype
- available types are "info", "warning", "error"ref
- the referenced component, null to be based on browser windowposition
- predefined positions.
Available options are:
duration
- the duration of notification in millisecond. If zero or
negative the notification does not dismiss until user left-clicks outside
of the notification box.Notification.show(String, String, Component, String, int)
public static final void showNotification(java.lang.String msg, java.lang.String type, Component ref, java.lang.String position, int duration, boolean closable)
msg
- the message to showtype
- available types are "info", "warning", "error"ref
- the referenced component, null to be based on browser windowposition
- predefined positions.
Available options are:
duration
- the duration of notification in millisecond. If zero or
negative the notification does not dismiss until user left-clicks outside
of the notification box.closable
- whether to close notification manually or not. If true there will be a
close button on notification message and won't close until user click the button
or duration time up, default false.Notification.show(String, String, Component, String, int, boolean)
public static final void showNotification(java.lang.String msg, java.lang.String type, Component ref, int x, int y, int duration)
msg
- the message to showtype
- available types are "info", "warning", "error"ref
- the referenced component, null to be based on browser windowx
- the horizontal position of the notification, aligned at top-left (in pixel)y
- the vertical position of the notification, aligned at top-left (in pixel)duration
- the duration of notification in millisecond. If zero or
negative the notification does not dismiss until user left-clicks outside
of the notification box.Notification.show(String, String, Component, int, int, int)
public static final void showNotification(java.lang.String msg, java.lang.String type, Component ref, int x, int y, int duration, boolean closable)
msg
- the message to showtype
- available types are "info", "warning", "error"ref
- the referenced component, null to be based on browser windowx
- the horizontal position of the notification, aligned at top-left (in pixel)y
- the vertical position of the notification, aligned at top-left (in pixel)duration
- the duration of notification in millisecond. If zero or
negative the notification does not dismiss until user left-clicks outside
of the notification box.closable
- whether to close notification manually or not. If true there will be a
close button on notification message and won't close until user click the button
or duration time up, default false.Notification.show(String, String, Component, int, int, int, boolean)
public static final void showBusy(java.lang.String msg)
It is usually used with Events.echoEvent(java.lang.String, org.zkoss.zk.ui.Component, java.lang.String)
to prevent the user to click another buttons or components.
To cover only a particular component, use showBusy(Component, String)
.
To close, use clearBusy()
.
msg
- the message to show. If null, the default message (processing)
is shown.clearBusy()
public static final void showBusy(Component comp, java.lang.String msg)
To execute a long operation asynchronously, the developer can use
a working thread,
or use EventQueue.subscribe(org.zkoss.zk.ui.event.EventListener,boolean)
.
See also Long Operations
comp
- the component that the busy message to cover.
Ignored if null. Notice that if the component is not found,
the busy message won't be shown. In additions, the busy message
is removed automatically if the component is detached later.
To manually remove the busy message, use clearBusy(Component)
msg
- the message to show. If null, the default message (processing)
is shown.clearBusy(Component)
public static final void clearBusy()
showBusy(String)
public static final void clearBusy(Component comp)
comp
- the component that the busy message to cover.showBusy(Component, String)
public static final void resize(Component comp)
public static final void reloadMessages(java.util.Locale locale) throws java.io.IOException
Notice that this method only reloads the standard messages. The application has to update the component's content (such as labels) manually if necessary.
Limitation: it reloads only the messages of ZK Client Engine and ZUL components. It does not reload messages loaded by your own JavaScript codes.
locale
- the locale. If null, Locales.getCurrent()
is assumed.java.lang.UnsupportedOperationException
- if the device is not ajax.java.io.IOException
public static final void log(java.lang.String msg)
data[0]: the title
public static final void log(java.lang.Object msg)
msg
- message, cast to Stringpublic static final void loadScript(java.lang.String url)
By default, this method won't cache the JavaScript file, but you can
enable it by invoking loadScript(String, String, boolean)
.
url
- the JavasScript file path, it will be encoded with
Encodes.encodeURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, String)
if any.Encodes.encodeURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
,
loadScript(String, String, boolean)
public static final void loadScript(java.lang.String url, java.lang.String callback, boolean cache)
url
- the JavasScript file path, it will be encoded with
Encodes.encodeURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, String)
if any.callback
- a callback script to execute when the JavaScript file has loaded.cache
- true means the url will be cached and executed only once.Encodes.encodeURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
public static final void loadCSS(java.lang.String url)
url
- the URL of the CSS filepublic static final void sendClientCommand(Component component, java.lang.String commandName, java.lang.Object data)
component
- target componentcommandName
- the command name which would be triggered in clientdata
- data which would be sent to clientpublic static final void syncErrorbox()
public static final void syncErrorbox(Component component)
component
- target componentpublic static final void focus(Component component)
component
- target componentpublic static final void focus(java.lang.String selector)
selector
- the selector stringSelectors.find(org.zkoss.zk.ui.Page, String)
,
Selectors.find(Component, String)
Copyright © 2005-2023 Potix Corporation. All Rights Reserved.